Wednesday, May 31, 2006

Struts Tips - Multi select list box "deselect all" problem

Problem
De-selecting all items from the multi select list box does not update the action form. Action form will still have the values pertaining to the previous selection.

Cause
When no items are selected from the list box, no data is sent for the parameter.

Solution
Add the below check in the action class:-

if (request.getParamter("list box name") == null) {
form.set(new String[]{});
}


This will clear the values of the earlier selection from the list box property