Hi Simon,

I struggled with this for quite a while.  The nested beans are being set to
null when you post.  It just seemed logical that these nested beans should
be automatically re-populated from the form.  Basically, I couldn't figure a
way to make struts do it automatically for me, I think it's a limitation of
the populate() method.  There may be a way if you use a BeanInfo class to
describe your nested beans (not sure though, I'm not that familiar with how
BeanInfo classes work).  My work around was to manually re-populate the
beans 'the old fashioned way' in the action classs by getting the form
variables from the request object.

For example, my PersonForm class has an Address bean nested in it.

private int personId;
private String lname;
private String fname;
...
public AddressInfo homeAddress; // Note: this is public so I can call
setters on it


I display the address info just fine on the page with the nested dot
notation:
...
<html:text property="homeAddress.address1" size="90" maxlength="100"/>
<html:text property="homeAddress.address2" size="90" maxlength="100"/>
<html:text property="homeAddress.city" size="20" maxlength="30"/>
...


When I post to the action class I have to manually re-populate the
homeAddress bean:

...
PersonForm personForm = (PersonForm)form;
personForm.homeAddress.setAddress1(request.getParameter("homeAddress.address
1"));
personForm.homeAddress.setAddress2(request.getParameter("homeAddress.address
2"));
personForm.homeAddress.setCity(request.getParameter("homeAddress.city"));
...


That's it.  If anyone knows how to do it differently that info would be
appreciated.
hth,
Chuck

-----Original Message-----
From: Simon Liang [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 20, 2001 8:34 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: Nested Beans on form not being updated


Hello:

I am experiencing the same problem. Basically on a post to the form. the
nested beans are set to null. Is this right? Are we doing something wrong or
misunderstanding something here?????

<!-- here is the code fragment -->
<html:form>
...
<html:text name="userprofileForm" property="name" styleClass="select"/>
...
<html:text name="userprofileForm" property="profileWebAddress.mail"
styleClass="select"/>
...
</html:form>
<!-- end code fragment -->

On the post, the object 'profileWebAddress' is null. Is this valid? Can
someone shine some light into this?

Please help.

Simon



-----Original Message-----
From: Chuck Stern [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 18, 2001 1:24 AM
To: Struts-User
Subject: Nested Beans on form not being updated


Hi,

I have a form with multiple beans on it but the nested beans are not getting
updated when I change the data and submit.  I use dot notation to display
the data from the beans and populate the form, that works great.  After
submitting, the nested beans are set to null.

I've tried putting the form bean in both request and session but get the
same results.  Any ideas?


Thanks,
Chuck


============================================================================
This message is intended only for the use of the Addressee(s) and may
contain information that is PRIVILEGED and CONFIDENTIAL. If you are not
the intended recipient, dissemination of this communication is prohibited.
If you have received this communication in error, please erase all copies
of the message and its attachments and notify [EMAIL PROTECTED]
immediately.
============================================================================

Reply via email to