struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <>
Subject Re: <s:checkboxlist> and the CheckBox Interceptor
Date Thu, 06 May 2010 17:30:35 GMT
On 5/6/10 4:15 AM, RogerV wrote:
> The documentation says that the checkbox 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'."

So let's think about how that works:
If a form includes <input type="checkbox" name="foo" value="true" /> 
then the browser either includes foo=true as a parameter or does not.
The checkbox tag also causes the form to include <input type="hidden" 
name="__checkbox_foo" value="true" /> .  When the interceptor runs, if 
it sees a value for __checkbox_foo but none for foo then it knows the 
checkbox was not checked and can add as a request parameter the field 
foo with the appropriate value for a non-checked checkbox.

> Should the interceptor work with<s:checkboxlist>  or does it only work with
> <s:checkbox>. All I'm getting back from the<s:checkboxlist>  is a list of
> selected checkboxes, there's no indication of any that are unselected.

When you're including in the form a bunch of checkboxes with the same 
name attribute, the browser will submit those that were checked and not 
submit anything for those that were not.  Since they all get submitted 
with the same name, I can think of no simple way for the server to 
distinguish between them, or thus detect which checkboxes were not 
submitted (which would then enable the interceptor to decide which 
hidden fields need to be introduced into the parameter set.

> Given the trouble I've been having with the<s:checkboxlist>  tag recently I
> thought I'd ask before I dive in.

I could be wrong about this -- I've not used the checkboxlist tag 
myself, and have not read any documentation before writing this response 
-- I'm just providing my gut reaction on how the underlying html form 
mechanisms mean the same checkbox solution would not work easily if the 
checkbox's name were not unique.  Maybe another solution has been 
figured out and implemented already.  For example, if there were a set 
of hidden fields corresponding to the checkboxes, it might be possible 
to figure out which of those values were not included in those submitted 
by the checkboxes, and set some other request parameters to match (so 
you could end up with a list of checked values (setFoo(List<String>)) 
and a list of unchecked values (setNotFoo(List<String>))).  I'd look in 
the documentation, the .ftl files implementing the checkboxlist tag to 
see if there are any useful hidden fields included in the form, and the 
interceptor code to see exactly what it does (especially when multiple 
request parameters have the same name).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message