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

 

 

Reply via email to