Announcement Announcement Module
Collapse
No announcement yet.
binding causes null properties for nested object Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • binding causes null properties for nested object

    I have a UserForm with a nested User class. When I submit the form, the properties are all set to null and don't seem to be binding the nested form values. It is picking up the UserForm properties correctly.

    I know this has to be some simple syntax problem, but I've been racking my brain over it for too long and need some help!

    Kim


    edit.jsp:
    Code:
    	<spring&#58;bind path="userForm.user.firstName">
    		<input type="text" name="firstName" id="firstName" value="$&#123;status.value&#125;" class="text"/>
    		<c&#58;if test="$&#123;not empty status.errorMessage&#125;"><span class="fieldError">$&#123;status.errorMessage&#125;</span></c&#58;if>
    	</spring&#58;bind>
    UserForm.java:
    Code:
    public class UserForm &#123;
        
        private User user;
        private boolean newUser;
        private String repeatedPassword;
    
    // getters and setters follow
    &#125;
    User.java:
    Code:
    public class User implements Serializable&#123;
        
        static final long serialVersionUID = -3202570521013016218L;
        
        private String username;
        private String password;
        private boolean enabled;
        private String firstName;
        private String lastName;
    
    // getters and setters follow
    &#125;

    action-servlet.xml:
    Code:
        <bean id="userFormController" class="com.tripshare.web.manage.UserFormController">
            <property name="commandName"><value>userForm</value></property>
            <property name="commandClass"><value>com.example.web.manage.UserForm</value></property>
            <property name="validator"><ref bean="beanValidator"/></property>
            <property name="formView"><value>manage/users/edit</value></property>       
            <property name="successView"><value>redirect&#58;/manage/users/index.html</value></property>
    
            <property name="sessionForm"><value>true</value></property>
            <property name="bindOnNewForm"><value>true</value></property>
        </bean>

  • #2
    I neglected to mention I'm using 1.2-rc2.

    Comment


    • #3
      As I guessed, it was a simple syntax problem. I was using Matt Raible's equinox jsp as a template, and the 'name' attribute of the text field was hard-coded to 'firstName'. As I am using a nested bean, the actual name of the form needed to be 'user.firstName'.

      This can be obtainedby using the ${status.expression} variable for the field 'name' attribute inside the <spring:bind> tag, as per the jpetstore example.

      Comment

      Working...
      X