Hi again, all,
I have made a form using the multibox technique. Following the instructions of different tutorials, I have also successfully made certain checkboxes on the form checked by default when the page loads.
Here is a quick and dirty example of the process I used:
//ActionForm:
private String[] selectedItems = {"FedEx"};
private String[] items = {"UPS","FedEx","Airborne"};
public void reset(){
this.selectedItems=null;
}
public String[] getSelectedItems() { return this.selectedItems; }
public void setSelectedItems(String[] selectedItems) { this.selectedItems = selectedItems; }
public String[] getItems() { return this.items; }
public void setItems(String[] items) { this.items = items; }
//JSP:
<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item"/>
</html:multibox>
<bean:write name="item"/>
</logic:iterate>
//struts-config.xml
<form-property name="items" type="java.lang.String[]" />
<form-property name="selectedItems" type="java.lang.String[]" />
However, my problem is that if a user unchecks an item that was checked by default, that value is sitll in the sectedItems[] array.
So, example scenario:
-user loads form.
-by default "FedEx" checkbox is checked, like it's supposed to be
-user unchecks "FedEx" and checks "Airborne". User clicks submit
-Action class does a get on the selectedItems[] array.
-selectedItems[] contains FedEx AND Airborne, when it should only contain Airborne!
Many FAQ sites have indicated to have a reset() method in your ActionForm, which sets all your checkboxes to null or false in order to solve the "my checkboxes don't uncheck" problem. However, my situation is a little different because I am using multibox. However, as you can see in the code above, I still tried to do a reset() method, setting the arrays to null... but this did not help.
Any ideas?
Thanks! I really appreciate your time.