Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: S2:The value of checkbox getted in server-side is "false" when no any checkbox been selected.

Denis Ling

2006-12-19

Replies:

Hi Dave Newton,

 Thanks for your reply quickly!

 please see my problem:

 generated HTML source segment by S2
...

<input type="checkbox" name="roleIds" value="ROLE_ADMIN" id="listRole_roleIds"/>
<input type="hidden" name="__checkbox_roleIds" value="ROLE_ADMIN"/>

<input type="checkbox" name="roleIds" value="ROLE_SUPER_USER"
id="listRole_roleIds"/>
<input type="hidden" name="__checkbox_roleIds" value="ROLE_SUPER_USER"/>

...


case1: if i checked all above checkboxs, the string array "
{"ROLE_ADMIN","ROLE_SUPER_USER"} " will be getted at server-side.
case2: if i only checked first checkbox, then at server-side the string
array "{"ROLE_ADMIN"}" will be getted.
case3: if i didn't select any checkbox, then at server-side the string array
" { "false" } " will be getted.

but in my opinion, the getted value should be NULL in case3. what's your
opinion?



2006/12/18, Dave Newton <DNewton@(protected)>:
>
> From: Denis Ling [mailto:denislingcn@(protected)]
> > the retrieved value of "roleId" is {"false"} when user doesn't select
> > any checkbox elements. In my opinion, this case should returns null
> > directly.
>
> Why?
>
> S2 automagically deals with one of the headaches of HTTP (not returning
> unchecked box values) by adding a hidden field to the form. This makes
> the server side code much cleaner, IMO.
>
> d.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>


--
Thanks & Regards
Denis Ling
©2008 junlu.com - Jax Systems, LLC, U.S.A.