{"id":1679,"date":"2016-09-21T10:26:56","date_gmt":"2016-09-21T10:26:56","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=1679"},"modified":"2019-04-08T12:51:11","modified_gmt":"2019-04-08T12:51:11","slug":"accessing-bean-values","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/accessing-bean-values\/","title":{"rendered":"Accessing Bean Values"},"content":{"rendered":"<p><strong>TestController.java<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n@RequestMapping(value=&quot;\/Control2&quot;, method=RequestMethod.POST)\r\npublic String TestMe2(Model model)\r\n{\r\n  Person objPerson = new Person();\r\n  objPerson.setName(&quot;Mugil&quot;);\r\n  objPerson.setAddress(&quot;Sample Address&quot;);\r\n  objPerson.setAge(&quot;27&quot;);\r\n\r\n  model.addAttribute(&quot;objPerson&quot;, objPerson);\r\n  return &quot;display&quot;;\r\n}\r\n<\/pre>\n<p><strong>display.jsp<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nPerson Name : ${objPerson.name}\r\nPerson Location : ${objPerson.location}\r\nPerson Age : ${objPerson.age}\r\nPerson Address : ${objPerson.address}\r\n<\/pre>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npublic class Person \r\n{\r\n private String Name;\r\n private String Location;\r\n private String Age;\r\n private String Address;\r\n\r\n public String getName() {\r\n\treturn Name;\r\n }\r\n public void setName(String name) {\r\n\tName = name;\r\n }\r\n public String getLocation() {\r\n\treturn Location;\r\n }\r\n public void setLocation(String location) {\r\n\tLocation = location;\r\n }\r\n\r\n .\r\n .\r\n .\r\n}\r\n<\/pre>\n<p><strong>How to Design Spring MVC for View Page<\/strong><\/p>\n<ol>\n<li>Have a isSuccess attribute in the bean<\/li>\n<li>Use when and choose to decide whether to form element or form value based on the value set in the isSuccess<\/li>\n<li>When isSuccess is set to true the show the form Value or show the form element else display the form element<\/li>\n<li>When adding a new values in through the form the bean would be set to isSuccess true<\/li>\n<li>Next time when the page gets loaded the form values filled before the click of the submit will be displayed a s form values.<\/li>\n<\/ol>\n<p><strong>How to access the bean values where the bean has sub bean<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nclass Student\r\n{\r\n String Name;\r\n Address houseAddress;\r\n .\r\n .\r\n}\r\n<\/pre>\n<p>For accessing values in Student bean the form elements should be<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npath=Name value=&quot;${student.Name}&quot;\r\n<\/pre>\n<p>For accessing values in Student Address bean the form elements should be<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\npath=Address.houseAddress value=&quot;${Student.Address.StreetName}&quot; \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>TestController.java @RequestMapping(value=&quot;\/Control2&quot;, method=RequestMethod.POST) public String TestMe2(Model model) { Person objPerson = new Person(); objPerson.setName(&quot;Mugil&quot;); objPerson.setAddress(&quot;Sample Address&quot;); objPerson.setAge(&quot;27&quot;); model.addAttribute(&quot;objPerson&quot;, objPerson); return &quot;display&quot;; } display.jsp Person Name : ${objPerson.name} Person Location : ${objPerson.location} Person Age : ${objPerson.age} Person Address : ${objPerson.address} public class Person { private String Name; private String Location; private String Age; private String Address;&hellip; <a href=\"https:\/\/codethataint.com\/blog\/accessing-bean-values\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[],"class_list":["post-1679","post","type-post","status-publish","format-standard","hentry","category-spring-mvc"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=1679"}],"version-history":[{"count":4,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1679\/revisions"}],"predecessor-version":[{"id":2628,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/1679\/revisions\/2628"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=1679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=1679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=1679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}