The trick is understanding the request processing life-cycle. The following is the sequence of events:

  - Struts either instantiates the action form or, if you use session
    scoped forms and one already exists, retrieves it from the session

  - Struts calls reset() on the form (I *think* in all cases, but it
    may only do this when retrieving a form from session scope)

  - if this request is a form submit, the form data is stored into
    the form bean

  - Struts calls your action, passing in the form bean

  - In your pre-populate action, you would set the boolean properties
    in the form ready for display; in your form processing action, you
    would read their state reflecting the request data

  - You return a forward mapping that Struts uses to render the next
    view

So, you set everything to false in reset(); *after* that, your setup action gets the opportunity to set the properties as appropriate for display. On the next request, when the form is submitted, reset() is called which clears the boolean properties and then they're updated based on the form data.

L.

Per Jørgen Walstrøm wrote:
hello,
you are right, I do have access to the POJO and the properties and I am able to 
pre-populate the form. However, the checkboxes are rendered dynamically in the 
jsp from the getRestrictive() method of my GeSectionComponent. I can't really 
set them all to false beforehand, because then they would not be populated 
right, I guess... Don't know if I'm making myself clear, but I can't see how I 
can reset my checkboxes without resetting the actual properties. Should I try 
to use a multibox with an array of dynamic size (i.e. a size which depends on 
the size of the geSectionComponents-Collection)?

/pj

-----Opprinnelig melding-----
Fra: Laurie Harper [mailto:[EMAIL PROTECTED] Sendt: 1. desember 2005 00:03
Til: user@struts.apache.org
Emne: Re: checkbox for nested collection

Per Jørgen Walstrøm wrote:
hello,
I have the following code in my jsp:

<nested:iterate id="sectionComponent" property="geSectionComponents">
  <nested:checkbox property="restrictive"/> </nested:iterate>

my Collection geSectionComponents contains objects of type GeSectionComponent

GeSectionComponent.java (an auto-generated Hibernate POJO), contains the 
following field (with getter and setter):
private Boolean restrictive;

How do I go about to make sure Struts detects when I uncheck a checkbox? I am 
aware of that I should set all corresponding boolean properties to false in the 
reset()-method, but in this case I do not have any direct access to those 
properties.

any suggestions?

What do you mean you don't have any direct access to those properties? You must be creating a reference to that object (or retrieving one through Hibernate) somewhere in your code. Assuming you're storing the POJO in your form bean as part of pre-population, you can then access it in your reset() method.

L.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to