You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Richard Sayre <ri...@gmail.com> on 2009/04/15 12:59:48 UTC

Set Unchecked Value in the Checkbox Interceptor

The Struts 2 docs says the following about the Checkbox Interceptor:

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

Where in code can I call the  setUncheckedValue(String uncheckedValue) from?

The problem I am facing is the fieldValue (HTML value) if the check
box is an int.  My action has an int[] id.  I would like to set the
value of an array element to 0 when it is not checked.  I assumed
because the current interceptor inserts "false" for unchecked boxes
this would automatically get converted to an int because my action
uses an int array.  This does not occur.  Any advice would be
appreciated.

Thank you,

Rich

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Set Unchecked Value in the Checkbox Interceptor

Posted by Richard Sayre <ri...@gmail.com>.
I think I found the problem.  All of my check boxes have the same
name.  After examining the code in the interceptor:

 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);
}

}

The name will be in the parameters since they are all the same.  So
when it finds one that is unchecked (not submitted), it will not get
added since the name is already there from a check box that has been
submitted.  I will have to find another way to achieve this since my
check box list is dynamic and can be any size.  I will post some code
when I finish.

Rich



On Wed, Apr 15, 2009 at 9:05 AM, Richard Sayre <ri...@gmail.com> wrote:
> After reading some more documentation I tried :
>
>  <interceptor-ref name="completeDefault">
>                <param name="checkbox.uncheckedValue">-1</param>
>  </interceptor-ref>
>
> completeDefault is a stack I created which includes the checkbox interceptor.
>
> This is still not setting the value in my int array.
>
>
>
> On Wed, Apr 15, 2009 at 8:29 AM, Richard Sayre <ri...@gmail.com> wrote:
>> The Struts 2 docs says the following about the Checkbox Interceptor:
>>
>> setUncheckedValue - The default value of an unchecked box can be
>> overridden by setting the 'uncheckedValue' property.
>>
>> Where in code can I call the  setUncheckedValue(String uncheckedValue) from?
>>
>> The problem I am facing is the fieldValue (HTML value) if the check
>> box is an int.  My action has an int[] id.  I would like to set the
>> value of an array element to 0 when it is not checked.  I assumed
>> because the current interceptor inserts "false" for unchecked boxes
>> this would automatically get converted to an int because my action
>> uses an int array.  This does not occur.  Any advice would be
>> appreciated.
>>
>> Thank you,
>>
>> Rich
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Set Unchecked Value in the Checkbox Interceptor

Posted by Richard Sayre <ri...@gmail.com>.
After reading some more documentation I tried :

 <interceptor-ref name="completeDefault">
                <param name="checkbox.uncheckedValue">-1</param>
 </interceptor-ref>

completeDefault is a stack I created which includes the checkbox interceptor.

This is still not setting the value in my int array.



On Wed, Apr 15, 2009 at 8:29 AM, Richard Sayre <ri...@gmail.com> wrote:
> The Struts 2 docs says the following about the Checkbox Interceptor:
>
> setUncheckedValue - The default value of an unchecked box can be
> overridden by setting the 'uncheckedValue' property.
>
> Where in code can I call the  setUncheckedValue(String uncheckedValue) from?
>
> The problem I am facing is the fieldValue (HTML value) if the check
> box is an int.  My action has an int[] id.  I would like to set the
> value of an array element to 0 when it is not checked.  I assumed
> because the current interceptor inserts "false" for unchecked boxes
> this would automatically get converted to an int because my action
> uses an int array.  This does not occur.  Any advice would be
> appreciated.
>
> Thank you,
>
> Rich
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org