You need to implement the reset() method, as Erik has mentioned. It was
created to solve exactly the problem you are having.

--
Martin Cooper


----- Original Message -----
From: "Krueger, Jeff" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 02, 2001 11:59 AM
Subject: RE: multibox and reset() "ERIK"


>
> I haven't tried the reset method, but I am setting the default
> values in the constructor.  I'm not sure how those two will help with my
> problem though.  Maybe let me try and explain it a little more.  I go to
the
> page for the first time and the formBean is created, everything is blank
and
> ok.  The user then selects 4 out of ten boxes and submits the form.  So
now
> I have a string array with 4 items in it.  The user returns to the page
and
> those four items are then selected out of the ten.  Then the user
unselects
> all items and submits the form.  The form has already been created so the
> constructor shouldn't fire and since there are no check boxes selected or
> submitted the setMethod won't get called and I will be left with the same
> array of four items.  Maybe I should have had them reset the form instead
of
> submitting a empty one here?  So this is where I added the code to my
action
> to see if no check boxes were submitted and then call the set method and
> pass in a string array of length 0.
>
>
> Jeff
>
>
> -----Original Message-----
> From: Erik Hatcher [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, October 02, 2001 11:46 AM
> To: [EMAIL PROTECTED]
> Subject: Re: multibox and reset() "ERIK"
>
>
> The better way is just what was mentioned.... set your values to null
> (false?) in the reset method.   But if you are using Struts 1.0 and not a
> more recent build, also setting them in the constructor or initial values
> when defined is a good idea to default them in the case you are navigating
> directly to the JSP page rather than going through a Struts action to get
to
> the JSP page.
>
> So more succintly, initialize values in reset and that should fix the
issue
> you described.   Did you try that?
>
>     Erik
>
>
> ----- Original Message -----
> From: "Krueger, Jeff" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, October 02, 2001 7:49 AM
> Subject: RE: multibox and reset() "ERIK"
>
>
> > Thanks Erik for the extra info.  I was thinking that was the problem I
was
> > having.  One idea that I had was to check in my action class to see if
any
> > check boxes were on the request and if not then call the set method
myself
> > setting it to null.  Does anyone know of a better way to do this.
> >
> > Thanks
> >
> > Jeff
> >
> >
> > -----Original Message-----
> > From: Erik Hatcher [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, October 02, 2001 8:49 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: multibox and reset() "ERIK"
> >
> >
> > Jeff,
> >
> > No, my patch did not fix this particular case.   Here is what is
happening
> > in your scenario: checkboxes do not submit a value if they are
unchecked,
> > therefore Struts has no way of knowing of their existence on the
original
> > HTML form and thus does not call any setters.  The reset method is where
> you
> > implement setting all your checkboxes (and likely other HTML field
types)
> to
> > their default (false, in your case) value.
> >
> > My patch was for the case where the ActionForm bean was created by a JSP
> > page rather than ActionServlet, and reset was not called at that point.
> In
> > your case, the ActionForm bean is being created (in the last request you
> > speak of) by ActionServlet, so reset should be called - this is all
> assuming
> > you are going through a Struts action for that request.
> >
> > My patch has been committed to Struts CVS, so its available in the
nightly
> > builds (I presume, unless those builds are running on a different branch
> or
> > something).
> >
> >     Erik
> >
> > ----- Original Message -----
> > From: "Krueger, Jeff" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Tuesday, October 02, 2001 7:07 AM
> > Subject: RE: multibox and reset() "ERIK"
> >
> >
> > > Erik,
> > >
> > > I believe your patch will solve my problem but I'm not sure.  I have
> > > a page with many multibox tags on it.  When I select several of them
my
> > form
> > > bean is correctly populated with a string array.  If I come back to
the
> > page
> > > all the correct boxes are checked.  If I remove all the checks and
click
> > > submit then my string array is left to what it was before.  I assume
> this
> > is
> > > because there is no mutliboxes being submitted to the server,
therefore
> > the
> > > setMethod is never getting called.  Is that what you patch fixed, if
so
> do
> > > you know the status of that making it into a build?
> > >
> > > Thanks
> > >
> > > Jeff
> > >
> > >
> > > -----Original Message-----
> > > From: Erik Hatcher [mailto:[EMAIL PROTECTED]]
> > > Sent: Friday, September 14, 2001 8:24 PM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: multibox and reset()
> > >
> > >
> > > reset is currently not called if <html:form> creates the form bean,
> which
> > > happens if you go to the JSP page directly without hitting
ActionServlet
> > > first.
> > >
> > > I've submitted a patch to fix this, but it has not been committed yet.
> > >
> > >     Erik
> > >
> > >
> > > ----- Original Message -----
> > > From: "Renaud Waldura" <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Cc: <[EMAIL PROTECTED]>
> > > Sent: Friday, September 14, 2001 10:12 AM
> > > Subject: Re: multibox and reset()
> > >
> > >
> > > > The signature for reset() is the following:
> > > >
> > > > void reset(ActionMapping, HttpServletRequest)
> > > >
> > > > I don't know whether setting the array reference is null is enough,
or
> > you
> > > > truly need to create a zero-length array like in your example below.
> > > >
> > > > I set mine to null, it seemed to work.
> > > >
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Dirk Jaeckel" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Friday, September 14, 2001 6:26 AM
> > > > Subject: multibox and reset()
> > > >
> > > >
> > > > > Hi!
> > > > >
> > > > >
> > > > > I am having trouble resetting a StringArray that is connected to a
> > > > <html:multibox>-tag.
> > > > >
> > > > > HTML-Example:
> > > > >
> > > > > <html:form action="/map" method="GET">
> > > > > <html:multibox value="parking" property="layer"/>
> > > > > <html:multibox value="petrol" property="layer"/>
> > > > >
> > > > > <html:image property="layers" page="/img/update.gif"/>
> > > > >
> > > > > </html:form>
> > > > >
> > > > >
> > > > > Corresponding ActionForm:
> > > > >
> > > > > public class MapForm extends ActionForm {
> > > > >
> > > > >         private String[] _on = new String[0];
> > > > >
> > > > >         public void reset() {
> > > > > _on = new String[0];
> > > > >         }
> > > > >
> > > > >         public void setLayer(String in) {
> > > > > _on = in;
> > > > >         }
> > > > >
> > > > >         public String[] getLayer() {
> > > > > return _on;
> > > > >
> > > > >         }
> > > > > }
> > > > >
> > > > > The Manual told me to use the reset()-method to set The Array to
the
> > > > length 0, but reset() is never called.
> > > > >
> > > > >
> > > > > Dirk
> > > > >
> > > > >
> > > >
> > > >
> > >
> >


Reply via email to