You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by pallav_bora <pa...@rediffmail.com> on 2009/09/04 20:16:37 UTC

Checkbox and hidden field

Hi I am using Struts 2.1.6

I am using simple theme. When I use a checkbox tag , a hidden field is
automatically iserted in the final HTML. Please let me know how to get rid
of this hidden field. I have given code sample below:

Code in JSP:

<s:checkbox label="checkbox test"  name="checkboxField1" value="aBoolean"
fieldValue="true" />

Code in HTML:

<input type="checkbox" name="checkboxField1" value="true"
id="formId_checkboxField1"/>
<input type="hidden" id="__checkbox_formId_checkboxField1"
name="__checkbox_checkboxField1" value="true" />

Thanks

Pallav

-- 
View this message in context: http://www.nabble.com/Checkbox-and-hidden-field-tp25299309p25299309.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Checkbox and hidden field

Posted by Chris Pratt <th...@gmail.com>.
You can either use a plain old <input type="checkbox"/>  (since you're using
the simple theme anyway and the struts internal support won't work without
the hidden field).  Or you can edit the FreeMarker template in the simple
theme.  But both of these will kill Struts' ability to inject the proper
value into your action for you.
  (*Chris*)

On Fri, Sep 4, 2009 at 3:59 PM, Tommy Pham <to...@yahoo.com> wrote:

> ----- Original Message ----
> > From: pallav_bora <pa...@rediffmail.com>
> > To: user@struts.apache.org
> > Sent: Friday, September 4, 2009 11:16:37 AM
> > Subject: Checkbox and hidden field
> >
> >
> > Hi I am using Struts 2.1.6
> >
> > I am using simple theme. When I use a checkbox tag , a hidden field is
> > automatically iserted in the final HTML. Please let me know how to get
> rid
> > of this hidden field. I have given code sample below:
> >
> > Code in JSP:
> >
> >
> > fieldValue="true" />
> >
> > Code in HTML:
> >
> >
> > id="formId_checkboxField1"/>
> >
> > name="__checkbox_checkboxField1" value="true" />
> >
> > Thanks
> >
> > Pallav
> >
> > --
> > View this message in context:
> > http://www.nabble.com/Checkbox-and-hidden-field-tp25299309p25299309.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
>
> I haven't had the chance to look at Struts' source code yet but I think
> it's there so the action class can tell the value of checkbox submission to
> set the value of the corresponding field.  The value 'on' of the checkbox is
> submitted only if the checkbox is 'checked'.  I could be wrong.  (I noticed
> that hidden field too when I used the checkbox.  If you noticed, the tags
> reference saids 'name' is optional.  But if you omit it, you'll get null
> exception. )
>
> Regards,
> Tommy
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Checkbox and hidden field

Posted by Tommy Pham <to...@yahoo.com>.
----- Original Message ----
> From: pallav_bora <pa...@rediffmail.com>
> To: user@struts.apache.org
> Sent: Friday, September 4, 2009 11:16:37 AM
> Subject: Checkbox and hidden field
> 
> 
> Hi I am using Struts 2.1.6
> 
> I am using simple theme. When I use a checkbox tag , a hidden field is
> automatically iserted in the final HTML. Please let me know how to get rid
> of this hidden field. I have given code sample below:
> 
> Code in JSP:
> 
> 
> fieldValue="true" />
> 
> Code in HTML:
> 
> 
> id="formId_checkboxField1"/>
> 
> name="__checkbox_checkboxField1" value="true" />
> 
> Thanks
> 
> Pallav
> 
> -- 
> View this message in context: 
> http://www.nabble.com/Checkbox-and-hidden-field-tp25299309p25299309.html
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

I haven't had the chance to look at Struts' source code yet but I think it's there so the action class can tell the value of checkbox submission to set the value of the corresponding field.  The value 'on' of the checkbox is submitted only if the checkbox is 'checked'.  I could be wrong.  (I noticed that hidden field too when I used the checkbox.  If you noticed, the tags reference saids 'name' is optional.  But if you omit it, you'll get null exception. )

Regards,
Tommy


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