You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Ned Collyer (JIRA)" <ji...@apache.org> on 2007/06/12 09:11:28 UTC

[jira] Issue Comment Edited: (WW-992) Fixes broken checkbox and checkboxlist implementation.

    [ https://issues.apache.org/struts/browse/WW-992?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_41225 ] 

Ned Collyer edited comment on WW-992 at 6/12/07 12:10 AM:
----------------------------------------------------------

This has not been fixed for checkboxlist.ftl - see svn changelist through jira - u can see it has not been touched

The checkboxlist does not use the checkbox tag.

I have tried unsuccessfully fixing just the checkboxlist.ftl file, but it appears to be a little more complicated than an individual checkbox.

-----

I've had a bit more of a look.  The following works near the end of /simple/checkboxlist.ftl

    <#if parameters.nameValue?exists>
        <input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.nameValue?html}"/>
    <#else>
        <input type="hidden" name="__checkbox_${parameters.name?html}" value=""/>
    </#if>

However, if the backing Collection has not been initialised, an exception occurs.


 was:
This has not been fixed for checkboxlist.ftl - see svn changelist through jira - u can see it has not been touched

The checkboxlist does not use the checkbox tag.

I have tried unsuccessfully fixing just the checkboxlist.ftl file, but it appears to be a little more complicated than an individual checkbox.

-----

I've had a bit more of a look.  The following works

    <#if parameters.nameValue?exists>
        <input type="hidden" name="__checkbox_${parameters.name?html}" value="${parameters.nameValue?html}"/>
    <#else>
        <input type="hidden" name="__checkbox_${parameters.name?html}" value=""/>
    </#if>

However, if the backing Collection has not been initialised, an exception occurs.

> Fixes broken checkbox and checkboxlist implementation.
> ------------------------------------------------------
>
>                 Key: WW-992
>                 URL: https://issues.apache.org/struts/browse/WW-992
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Actions, Interceptors, Views
>    Affects Versions: WW 2.1.7
>         Environment: N/A
>            Reporter: Peter Molettiere
>            Assignee: Don Brown
>             Fix For: 2.0.0
>
>
> Checkbox handling is broken in webwork, since html checkboxes result in no parameter being sent with the form submission. The parameters interceptor has no way to see the missing checkbox fields, and so never unchecks things with "true" as default, and will not empty a list when a checkboxlist with nothing is selected is submitted.
> This fixes the issue.
> This will make your checkboxes and checkbox lists always set the appropriate values on your model, regardless of whether the checkbox is selected or not. Use the interceptor below in place of the default ParametersInterceptor, and insert this line at the beginning of the checkbox.ftl and checkboxlist.ftl templates:
> <input type="hidden" id="WebWork-checkboxExists" name="${parameters.name?html}" value="${parameters.fieldValue?html}"/>
> Here's the interceptor, written as a subclass of ParametersInterceptor. This could be rolled into ParametersInterceptor.
> import com.opensymphony.xwork.interceptor.ParameterNameAware;
> import com.opensymphony.xwork.interceptor.ParametersInterceptor;
> import com.opensymphony.xwork.util.OgnlValueStack;
> import java.util.Iterator;
> import java.util.Map;
> import java.util.TreeMap;
> public class CheckboxParameterInterceptor extends ParametersInterceptor {
>     protected void setParameters(Object action, OgnlValueStack stack, final Map parameters) {
>         ParameterNameAware parameterNameAware = (action instanceof ParameterNameAware)
>                 ? (ParameterNameAware) action : null;
>         for (Iterator iterator = (new TreeMap(parameters)).entrySet().iterator(); iterator.hasNext();) {
>             Map.Entry entry = (Map.Entry) iterator.next();
>             String name = entry.getKey().toString();
>             boolean acceptableName = acceptableName(name)
>                     && (parameterNameAware == null
>                     || parameterNameAware.acceptableParameterName(name));
>             if (acceptableName) {
>                 Object value = entry.getValue();
>                 if (name.startsWith("WebWork-checkboxExists")) {
>                     String[] checkboxes = (String[]) value;
>                     for (int i = 0; i < checkboxes.length; i++) {
>                         String checkbox = checkboxes[i];
>                         if (! parameters.containsKey(checkbox)) {
>                             stack.setValue(checkbox, new String[0]);
>                         }
>                     }
>                 }
>                 stack.setValue(name, value);
>             }
>         }
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.