title: Spring 3 MVC, Not able to access model object in JSP (Closed)
body: <p>i have one model object Person</p>
  
  <pre><code> public class Person {
  
           public String firstName;
           public String lastName;
  
           public String country;
           public String sex;
           private Integer age;  
  
  
          public String getSex() {
              return sex;
          }
  
          public void setSex(String sex) {
              this.sex = sex;
          }
  
          public String getCountry() {
              return country;
          }
  
          public void setCountry(String country) {
              this.country = country;
          }
  
          public String getLastName() {
              return lastName;
          }
  
          public void setLastName(String lastName) {
              this.lastName = lastName;
          }
  
  
  
          public String getFirstName() {  
              return firstName;  
          }  
  
          public void setFirstName(String firstName) {  
              this.firstName = firstName;  
          }  
  
          public Integer getAge() {  
              return age;  
          }  
  
          public void setAge(Integer age) {  
              this.age = age;  
          }  
  
          public String toString(){
              return firstName + " " + sex;
          }
  
  }
  </code></pre>
  
  <p>and in controller i populated reference data <strong>countryList</strong> in below method</p>
  
  <pre><code> @ModelAttribute
      public void populateCountryList(Model model){
          System.out.println("inside populateCountryList");
          Map&lt;String,String&gt; country = new LinkedHashMap&lt;String,String&gt;();
          country.put("Select", "-----Select------");
          country.put("US", "United Stated");
          country.put("CHINA", "China");
          country.put("SG", "Singapore");
          country.put("MY", "Malaysia");
          country.put("MY1", "India");
          country.put("MY2", "UK");
          country.put("MY3", "SA");
          country.put("MY4", "Newzeland");
  
          model.addAttribute("countryList", country);     
  
      }
  </code></pre>
  
  <p>Also populated <strong>Person</strong>  object in another method</p>
  
  <pre><code> @ModelAttribute
      public Person populateModel(){
          System.out.println("inside populateCountry");
          Person person = new Person();
          person.setCountry("India");
          person.setSex("M");
          return person;
      }
  </code></pre>
  
  <p>Now in jsp my components are text boxes for firstName, age, dropdown for country and radio button for sex. I want the radio button for <strong>Sex (M)</strong> and in dropdown the country <strong>"India"</strong> be selected by default. My jsp is below.</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"  
      pageEncoding="ISO-8859-1"%&gt;  
  &lt;%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt;  
  ...  
  &lt;h1&gt;Person page&lt;/h1&gt;  
  &lt;p&gt;This is Person page&lt;/p&gt;  
  &lt;form:form method="POST" commandName="person" action="process-person.html"&gt;  
  &lt;table&gt;  
      &lt;tbody&gt;&lt;tr&gt;  
          &lt;td&gt;&lt;form:label path="firstName"&gt;Name:&lt;/form:label&gt;&lt;/td&gt;  
          &lt;td&gt;&lt;form:input path="firstName"&gt;&lt;/form:input&gt;&lt;/td&gt;  
      &lt;/tr&gt;
  
  
      &lt;tr&gt;  
          &lt;td&gt;&lt;form:label path="age"&gt;Age:&lt;/form:label&gt;&lt;/td&gt;  
          &lt;td&gt;&lt;form:input path="age"&gt;&lt;/form:input&gt;&lt;/td&gt;  
      &lt;/tr&gt; 
  
      &lt;tr&gt;
       &lt;td&gt;&lt;form:label path="country"&gt;Country:&lt;/form:label&gt;&lt;/td&gt;  
       &lt;td&gt; 
         &lt;form:select path="country"&gt;                   
                         &lt;form:options items="${countryList}" /&gt;
         &lt;/form:select&gt;       
        &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;
          &lt;td&gt;Sex :&lt;/td&gt;
          &lt;td&gt;&lt;form:radiobutton path="sex" value="M" /&gt;Male 
               &lt;form:radiobutton path="sex" value="F" /&gt;Female
          &lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;tr&gt;  
          &lt;td colspan="2"&gt;  
              &lt;input type="submit" value="Submit"&gt;  
          &lt;/td&gt;  
          &lt;td&gt;&lt;/td&gt;  
          &lt;td&gt;&lt;/td&gt;  
      &lt;/tr&gt;  
  &lt;/tbody&gt;&lt;/table&gt;    
  &lt;/form:form&gt;  
  </code></pre>
  
  <p>When i am running the application default values are not getting selected. I also tried to print Person object in jsp, it is printing the Person object value of its properties are getting null.</p>
  
  <p>Please suggest me what is wrong in this implementation.</p>
  
  <blockquote>
    <p>Solution
    In the handler method i have written the below code.</p>
  </blockquote>
  
  <pre><code>**@RequestMapping(value="/person-form")  
  public ModelAndView personPage() {  
      return new ModelAndView("person-page", "person", new Person());  
  }**  
  </code></pre>
  
  <p>so i've changed the code to</p>
  
  <pre><code>**@RequestMapping(value="/person-form")  
  public ModelAndView personPage() {  
      return new ModelAndView("person-page");  
  }**
  </code></pre>