FileDocCategorySizeDatePackage
CheckboxInterceptor.javaAPI DocExample3269Mon Jul 23 13:26:52 BST 2007org.apache.struts2.interceptor

CheckboxInterceptor

public class CheckboxInterceptor extends Object implements com.opensymphony.xwork2.interceptor.Interceptor
Looks for a hidden identification field that specifies the original value of the checkbox. If the checkbox isn't submitted, insert it into the parameters as if it was with the value of 'false'.

  • setUncheckedValue - The default value of an unchecked box can be overridden by setting the 'uncheckedValue' property.

Fields Summary
private static final long
serialVersionUID
Auto-generated serialization id
private String
uncheckedValue
Constructors Summary
Methods Summary
public voiddestroy()


       
    
public voidinit()

    
public java.lang.Stringintercept(com.opensymphony.xwork2.ActionInvocation ai)

        Map parameters = ai.getInvocationContext().getParameters();
        Map<String, String> newParams = new HashMap<String, String>();
        Set<String> keys = parameters.keySet();
        for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
            String key = iterator.next();

            if (key.startsWith("__checkbox_")) {
                String name = key.substring("__checkbox_".length());

                iterator.remove();

                // is this checkbox checked/submitted?
                if (!parameters.containsKey(name)) {
                    // if not, let's be sure to default the value to false
                    newParams.put(name, uncheckedValue);
                }
            }
        }

        parameters.putAll(newParams);

        return ai.invoke();
    
public voidsetUncheckedValue(java.lang.String uncheckedValue)
Overrides the default value for an unchecked checkbox

param
uncheckedValue The uncheckedValue to set

        this.uncheckedValue = uncheckedValue;