Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Nested Bean Properties

 
Fred Artes
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have some problem with nested bean properties. This is my situation

JSP


ACTIONFORM


BEAN CUSTOMER


BEAN ADDRESS


The select is showed correctly but on form submit idCity is not valued. Where am I wrong ?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts will only populate the property in your ActionForm bean, not in your Customer bean. Just remove the name attribute from your html:select tag and struts will assign the idCity value to the address bean in the ActionForm.
 
Fred Artes
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use



because I want use the same JSP for insert and modify. In my action I have boolean bNew
bNew = true --> insert
bNew = false --> modify



So in HTML code I have




How can I populate idCity on form submit ?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your ActionForm is in request scope, you will need to instantiate the Address option before Struts can populate its properties. Change line 1 of your ActionForm to:

If you do this, Struts should populate the idCity property of the Address in the ActionForm when the form is submitted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic