This interceptor is defined in the defaultStack. It is essential for handling HTML checkboxes, as unchecked checkboxes are not submitted as part of a form. This interceptor ensures that a value is always present for a checkbox, so that in the Action class, the property is not null.
The interceptor looks for a special hidden field in the form that is associated with the checkbox. This hidden field must have a name that starts with __checkbox_ followed by the name of the checkbox. For example, if your checkbox is named myCheckbox, the hidden field should be named __checkbox_myCheckbox.
When the form is submitted, the CheckboxInterceptor does the following:
__checkbox_, it extracts the name of the checkbox from it (e.g., myCheckbox).myCheckbox) exists in the request.false.__checkbox_ prefixed parameters from the request, so they are not processed further.This ensures that the Action property for the checkbox will be set to false instead of being null.
The <s:checkbox> tag from the Struts UI Tags library automatically generates this hidden field for you.
uncheckedValue - The default value for an unchecked box is false. You can override this by setting the uncheckedValue property on the interceptor.This interceptor does not have any known extension points.
The <s:checkboxlist> tag is used to render a list of checkboxes. When using this tag, the submitted values are populated into a Collection or an array in your Action. When using @StrutsParameter with a checkbox list, you must place the annotation on the setter method of the collection property.
public class MyAction extends ActionSupport { private Collection<String> mySelection; @StrutsParameter public void setMySelection(Collection<String> mySelection) { this.mySelection = mySelection; } @StrutsParameter public Collection<String> getMySelection() { return mySelection; } }