Generally, a good strategy is to have a "prepare" action and a "process" action.  Your 
"prepare" action is where you would set your boolean form properties.  You then 
forward to the JSP, which renders the checkboxes.  The "process" action (from 
submitting the form) will determine whether the checkboxes are set or not.

> -----Original Message-----
> From: Bjørn T Johansen [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 10, 2003 12:38 PM
> To: Struts Users Mailing List
> Subject: Re: Checkbox problem?
> 
> oki, maybe my explanation isn't the best :) (I know that I can't do it
> in the reset method, as it is clearly not working)  but I am still not
> sure where to put the code to set the checkbox to true then.
> As far as I know, the action class isn't called before after the form
> bean has called the reset method and the page has been rendered (and the
> submit button has been pressed), or is it something I am missing?
> 
> BTJ
> 
> On Tue, 2003-06-10 at 20:28, James Mitchell wrote:
> > On Tuesday 10 June 2003 14:11, Bjørn T Johansen wrote:
> > > You are missing my point! If I just could set the checkbox value to
> > > false in the reset method, everything is fine. But there are times
> when
> > > that value has to be reset to true and not false and if I do that in
> my
> > > reset method, I am not able to see of the user unchek the checkbox,
> > > because the boolean variable is still true after the form has been
> > > posted!
> >
> > No, actually *YOU* are missing the point!  Several people have tried to
> > explain how this works to you.
> >
> > So, for one last effort....
> >
> > <IMPORTANT>
> > DO *NOT* SET THE FIELDS YOU INTENT TO USE AS CHECKBOXES (booleans) TO
> TRUE IN
> > THE RESET METHOD!!!!!
> > </IMPORTANT>
> >
> > If you want the field to be true when the page is rendered, set it to
> true
> > from your action class, NOT in the reset of your formbean.
> >
> > I hope that clears it up for you.
> >
> >
> > >
> > >
> > > BTJ
> > >
> > > On Tue, 2003-06-10 at 19:22, Tor Henrik Hanken wrote:
> > > > [EMAIL PROTECTED]
> > > >
> > > > | Yes, but to clarify...
> > > > | I am showing a jsp page with values read from a database. If the
> > > > | checkbox value is true, how do I then make the checkbox on my jsp-
> page
> > > > | checked and how do I then find out if the checkbox has been
> unchecked?
> > > > | Do I have to manually read the posted data and see if the checkbox
> > > > | attribute is missing or is there a better way?
> > > >
> > > > I assume that you are using an Action with an ActionForm.
> > > >
> > > > To make the value of the checkbox come up correctly, import
> > > > struts tags into your jsp-page:
> > > >
> > > > <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="strb" %>
> > > > <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="strh" %>
> > > > <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="strl" %>
> > > >
> > > > Then use the Struts checkbox tag:
> > > >
> > > > <strh:checkbox property="done"/>
> > > >
> > > > Assuming that your form has the methods getDone and setDone,
> > > > these methods will be used to render the value of the checkbox
> > > > correctly.
> > > >
> > > > As to the question of boolean values that are set to false by the
> > > > user: You don't have to parse the posted data manually.  The
> > > > method reset() in ActionForm is run before the posted data is
> > > > used to populate the form.  Write your own reset() method where
> > > > you set the boolean fields to false.
> 
> 
> 
> ---------------------------------------------------------------------
> 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