You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nicolas Pottrain <np...@reference.be> on 2003/04/03 10:45:21 UTC

Resetting checkboxes in a multipage form

Hello everybody,

I'm trying to implement a multipage form, with at least one checkbox.
To solve the problem with unchecked boxes not being submitted to the server,
I implemented the reset() method to set my checkboxValue to false.

However this solution does not work in a multipage form,
as the reset() method is called for every page of my form,
even the pages where my checkbox is not on.

For ex. a 3 page form
I check the box on page1, submit and go to page 2 --> everything works fine
fill in page 2, submit and got to page3 --> not ok

reset is called --> checkboxvalue back to false, and my bean is not
repopulated with the correct value
because my checkbox was not on page2.

Does anybody know an elegant solution to this problem?
Or am I forced to put a hidden parameter with the same name/value pair as my
checkbox
on the pages where my checkbox is not on.

thx for your time,

Nicolas

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Resetting checkboxes in a multipage form

Posted by Gemes Tibor <ti...@i-trade.hu>.
Nicolas Pottrain írta:

>Does anybody know an elegant solution to this problem?
>  
>
Carry your input with the help of a hidden field.

Tib




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Resetting checkboxes in a multipage form

Posted by Nicolas De Loof <ni...@cgey.com>.
As you suggest, a solution is to use hidden fields on all pages for boolean (checkboxed) properties from other pages of
the "wizard-like" form.

As reset() gets the mapping I would suggest this :

- extend ActionMapping to add a new property "checkboxes"
- use this extended ActionMapping for your action, setting the new property with a comma separated list of boolean
properties that this mapping should handle :

<action className="com.foo.WizardActionMapping"
        name="wizardForm"
        type="...">
  <set-property property="checkboxes" value="checbox1, checkbox2" />
  <forward .../>
</action>

- in reset(), cast mapping to your extended mapping, and use it to get the list of boolean properties to reset. (this is
example test, not tested and should not compile)

resest(mapping, request) {
    if (mapping instanceOf WizardActionMapping) {
        WizardActionMapping wizardMapping = (WizardActionMapping) mapping;
        StringTokenizer tokenizer =
            new StringTokenizer(wizardMapping.getCheckBoxes(), ",");
        while (tokenizer.hasMoreToken()) {
            String checkbox = tokenizer.nextToken().trim();

            // reset checkbox
            if ("checbox1".equals(checkbox)) {
                checbox1 = false;
            }
            ...
        }
    }
}

If you find a good portable solution, you should redistribute it in Scaffold Struts tools (contribs), as I think it is a
common problem.

Hope it will help you.

Nico.


> Hello everybody,
>
> I'm trying to implement a multipage form, with at least one checkbox.
> To solve the problem with unchecked boxes not being submitted to the server,
> I implemented the reset() method to set my checkboxValue to false.
>
> However this solution does not work in a multipage form,
> as the reset() method is called for every page of my form,
> even the pages where my checkbox is not on.
>
> For ex. a 3 page form
> I check the box on page1, submit and go to page 2 --> everything works fine
> fill in page 2, submit and got to page3 --> not ok
>
> reset is called --> checkboxvalue back to false, and my bean is not
> repopulated with the correct value
> because my checkbox was not on page2.
>
> Does anybody know an elegant solution to this problem?
> Or am I forced to put a hidden parameter with the same name/value pair as my
> checkbox
> on the pages where my checkbox is not on.
>
> thx for your time,
>
> Nicolas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Resetting checkboxes in a multipage form

Posted by Andrew Hill <an...@gridnode.com>.
You will need to put conditional logic in your reset() method so that it
only resets checkbox values on the page that is being submitted and leaves
checkbox values for other pages well alone.

-----Original Message-----
From: Nicolas Pottrain [mailto:npottrain@reference.be]
Sent: Thursday, 3 April 2003 16:45
To: 'struts-user@jakarta.apache.org'
Subject: Resetting checkboxes in a multipage form


Hello everybody,

I'm trying to implement a multipage form, with at least one checkbox.
To solve the problem with unchecked boxes not being submitted to the server,
I implemented the reset() method to set my checkboxValue to false.

However this solution does not work in a multipage form,
as the reset() method is called for every page of my form,
even the pages where my checkbox is not on.

For ex. a 3 page form
I check the box on page1, submit and go to page 2 --> everything works fine
fill in page 2, submit and got to page3 --> not ok

reset is called --> checkboxvalue back to false, and my bean is not
repopulated with the correct value
because my checkbox was not on page2.

Does anybody know an elegant solution to this problem?
Or am I forced to put a hidden parameter with the same name/value pair as my
checkbox
on the pages where my checkbox is not on.

thx for your time,

Nicolas

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org