You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wiebe de Jong <wi...@shaw.ca> on 2004/03/17 21:14:52 UTC

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);

 

 


Re: SOLVED: Multibox problem when defaulted all on

Posted by as as <sa...@yahoo.com>.
Wiebe,
 
Nice to hear that.
Actually I tried implementing the rows in my table with checkboxes generated through html:checkbox and pull out the checked Items' array in my action class, as per Ted's online struts tip.
I couldnt get it to show me the array from httpRequest..
if possible could you post the snippets in the classes..
it would be a good learning experience for us...
 
Thanks!

Wiebe de Jong <wi...@shaw.ca> wrote:
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:

value="filler"/>

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:derickson@cmcflex.com] 
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:derickson@cmcflex.com]
> 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" 
> To: "Struts Users Mailing List" 
> 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" 
> > To: "Struts Users Mailing List" 
> > 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
> > > - 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:
> > >
> > >
> > >
> > > > > styleClass=">
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > >
> > >
> > > -----
> > >
> > > Action:
> > >
> > >
> > >
> > > String[] marketing = form.getMarketing();
> > >
> > > log.debug("marketing " + marketing.length);
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> 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


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

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam

Re: SOLVED: Multibox problem when defaulted all on

Posted by as as <sa...@yahoo.com>.
Wiebe,
 
Nice to hear that.
Actually I tried implementing the rows in my table with checkboxes generated through html:checkbox and pull out the checked Items' array in my action class, as per Ted's online struts tip.
I couldnt get it to show me the array from httpRequest..
if possible could you post the snippets in the classes..
it would be a good learning experience for us...
 
Thanks!

Wiebe de Jong <wi...@shaw.ca> wrote:
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:

value="filler"/>

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:derickson@cmcflex.com] 
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:derickson@cmcflex.com]
> 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" 
> To: "Struts Users Mailing List" 
> 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" 
> > To: "Struts Users Mailing List" 
> > 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
> > > - 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:
> > >
> > >
> > >
> > > > > styleClass=">
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > >
> > >
> > > -----
> > >
> > > Action:
> > >
> > >
> > >
> > > String[] marketing = form.getMarketing();
> > >
> > > log.debug("marketing " + marketing.length);
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> 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


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

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam

Re: SOLVED: Multibox problem when defaulted all on

Posted by as as <sa...@yahoo.com>.
Wiebe,
 
Nice to hear that.
Actually I tried implementing the rows in my table with checkboxes generated through html:checkbox and pull out the checked Items' array in my action class, as per Ted's online struts tip.
I couldnt get it to show me the array from httpRequest..
if possible could you post the snippets in the classes..
it would be a good learning experience for us...
 
Thanks!

Wiebe de Jong <wi...@shaw.ca> wrote:
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:

value="filler"/>

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:derickson@cmcflex.com] 
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:derickson@cmcflex.com]
> 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" 
> To: "Struts Users Mailing List" 
> 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" 
> > To: "Struts Users Mailing List" 
> > 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
> > > - 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:
> > >
> > >
> > >
> > > > > styleClass=">
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > > ...
> > >
> > > 
> > >
> > >
> > >
> > > -----
> > >
> > > Action:
> > >
> > >
> > >
> > > String[] marketing = form.getMarketing();
> > >
> > > log.debug("marketing " + marketing.length);
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> 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


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

Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam

SOLVED: Multibox problem when defaulted all on

Posted by Wiebe de Jong <wi...@shaw.ca>.
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:derickson@cmcflex.com] 
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:derickson@cmcflex.com]
> 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" <de...@cmcflex.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> 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" <wi...@shaw.ca>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > 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: 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
>
>
> ---------------------------------------------------------------------
> 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


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


Re: Multibox problem when defaulted all on

Posted by David Erickson <de...@cmcflex.com>.
> 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:derickson@cmcflex.com]
> 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" <de...@cmcflex.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> 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" <wi...@shaw.ca>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > 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: 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
>
>
> ---------------------------------------------------------------------
> 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: Multibox problem when defaulted all on

Posted by Wiebe de Jong <wi...@shaw.ca>.
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.

Wiebe

-----Original Message-----
From: David Erickson [mailto:derickson@cmcflex.com] 
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" <de...@cmcflex.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
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" <wi...@shaw.ca>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> 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: 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


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


Re: Multibox problem when defaulted all on

Posted by David Erickson <de...@cmcflex.com>.
Actually according to Ted inside the reset method your code should be:

marketing = new String[] {};

HTH,
David

----- Original Message ----- 
From: "David Erickson" <de...@cmcflex.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
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" <wi...@shaw.ca>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> 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: 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: Multibox problem when defaulted all on

Posted by David Erickson <de...@cmcflex.com>.
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" <wi...@shaw.ca>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org