Hey David, thanks for the clue: When nothing is selected, the browser
doesn't send anything back.

So, my hack to this problem is to always have at least one of the checkboxes
checked. To implement this hack, I changed the following:

Form:

private String[] marketingItems = {"filler", "accountHolder", "user2",
"user3", "user4", "user5"};

Jsp:

<tr style="display:none;"><td><html:multibox property="marketing"
value="filler"/></td></tr>

Now there is a hidden checkbox on my page that can't be tabbed to and turned
off. Since there will always be at least one checkbox on, the browser will
always return the checkbox list. The "display:none;" makes the checkbox
totally invisible.

It's a hack, but it works!!!

Wiebe

-----Original Message-----
From: David Erickson [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 17, 2004 1:48 PM
To: Struts Users Mailing List
Subject: Re: Multibox problem when defaulted all on

> I don't think I explained myself quite clearly.
>
> WORKS: All the checkboxes on the form default to on.
> WORKS: User leaves all checkboxes on.
> WORKS: User turns some of the checkboxes off.
> DOESN'T WORK: User turns all of the checkboxes off.
>
> In the last situation, the form reports to the action that the marketing
> array still has the value of {"accountHolder", "user2", "user3", "user4",
> "user5"}, even though the user turned all the checkboxes off.

This is because when nothing is selected, nothing gets sent to the form to
be populated, so assuming your form is in session scope, whatever you had in
there when it was rendered, is still in there.  That's why inside the reset
method of the form you need to empty that string array.  That way if there
are value submitted they will be populated, and if there are none, it will
stay at none.
-David

>
> Wiebe
>
> -----Original Message-----
> From: David Erickson [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 17, 2004 12:28 PM
> To: Struts Users Mailing List
> Subject: Re: Multibox problem when defaulted all on
>
> Actually according to Ted inside the reset method your code should be:
>
> marketing = new String[] {};
>
> HTH,
> David
>
> ----- Original Message ----- 
> From: "David Erickson" <[EMAIL PROTECTED]>
> To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> Sent: Wednesday, March 17, 2004 1:22 PM
> Subject: Re: Multibox problem when defaulted all on
>
>
> > I'm still a little hazy on when reset is called on forms, but you may
want
> > to try moving
> > marketing = marketingItems;
> >
> > to the forms constructor, so when the form is created the first time its
> > holding the default values.
> > And inside the reset method:
> >
> > marketing = null;
> >
> > -David
> >
> > ----- Original Message ----- 
> > From: "Wiebe de Jong" <[EMAIL PROTECTED]>
> > To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
> > Sent: Wednesday, March 17, 2004 1:14 PM
> > Subject: Multibox problem when defaulted all on
> >
> >
> > > I am having a problem with multibox. I need to have a set of
checkboxes
> to
> > > default on in my form. I found and followed Ted Husted's "Struts Tip
#7
> > > <http://husted.com/struts/tips/007.html>  - Use Multibox to manage
> > > checkboxes" and everything works well, except in one condition
explained
> > > below.
> > >
> > >
> > >
> > > When everything is defaulted on, and the user checks off the boxes but
> > > leaves at least one checked on, everything works as planned. However,
if
> > all
> > > the boxes are defaulted on (as in the code below) and the user checks
> all
> > > the boxes off, the marketing array is not updated. In this case, the
> form
> > > ends up telling me that the checkboxes are all on.
> > >
> > >
> > >
> > > How do I get it to work properly in this situation?
> > >
> > >
> > >
> > > -----
> > >
> > > Form:
> > >
> > >
> > >
> > > public void reset(ActionMapping mapping, HttpServletRequest request) {
> > >
> > > ...
> > >
> > >   marketing = marketingItems;
> > >
> > > }
> > >
> > >
> > >
> > > private String[] marketing = {};
> > >
> > > private String[] marketingItems =
> > > {"accountHolder","user2","user3","user4","user5"};
> > >
> > > public String[] getMarketing() { return this.marketing; }
> > >
> > > public void setMarketing(String[] marketing) { this.marketing =
> > marketing; }
> > >
> > >
> > >
> > > -----
> > >
> > > Jsp:
> > >
> > >
> > >
> > > <html:multibox property="marketing" value="accountHolder
> > styleClass="form"/>
> > >
> > > ...
> > >
> > > <html:multibox property="marketing" value="user2" styleClass="form"/>
> > >
> > > ...
> > >
> > > <html:multibox property="marketing" value="user3" styleClass="form"/>
> > >
> > > ...
> > >
> > > <html:multibox property="marketing" value="user4" styleClass="form"/>
> > >
> > > ...
> > >
> > > <html:multibox property="marketing" value="user5" styleClass="form"/>
> > >
> > >
> > >
> > > -----
> > >
> > > Action:
> > >
> > >
> > >
> > > String[] marketing = form.getMarketing();
> > >
> > > log.debug("marketing " + marketing.length);
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
>
> ---------------------------------------------------------------------
> 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]


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

Reply via email to