You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pr...@united.com on 2004/07/12 22:44:08 UTC

Can html:checkbox take only yes/true/on as value?

Hi, 

 

In regular HTML checkbox, the value of the checkbox can practically be 
anything. Does the struts html:checkbox limit us to just yes/true/on 
values? 

If I have a list of records that I get from the database and I want to 
display it with a checkbox at the left, the value of the checkbox being 
the id of the record, how do I do that? Should there be another hidden 
field for the checkbox with the actual value? And how do I connect the 
checkbox to its corresponding hidden field? 

 

I have searched high and low and found no clear explanation. I just want 
someone to explain this to me. 

 

Also how does the multibox fall into the picture? Can I use checkbox and 
multibox interchangeably? 

Thanks

Prashanthi



Re: Can html:checkbox take only yes/true/on as value?

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: <Pr...@united.com>
> In regular HTML checkbox, the value of the checkbox can practically be
> anything. Does the struts html:checkbox limit us to just yes/true/on
> values?

No, you can have anything you want as the value.  It might default to yes or
true, I haven't tried it.

> If I have a list of records that I get from the database and I want to
> display it with a checkbox at the left, the value of the checkbox being
> the id of the record, how do I do that?

Use the 'value' attribute of the <html:checkbox> tag, then if the box is
checked, that value will be submitted as the value of the form element.

(Checkboxes are special-- only successful/checked ones will be submitted, so
read the docs and reset them properly or you'll never be able to UNcheck
them.)

> Also how does the multibox fall into the picture? Can I use checkbox and
> multibox interchangeably?

No... checkbox is a single thing, and corresponds to a String property in
your Form bean.  Multibox corresponds to a String[], because you can choose
more than one item.  Here's an example of multibox:

    <c:forEach items="${accountMap}" var="item" >
       <html-el:multibox property="accounts" value="${item.key}"/>
       <c:out value="${item.key}"/> &nbsp;
       <c:out value="${item.value.costCenterDesc}"/> <br/>
    </c:forEach>

Technically, I suppose you could use multibox in place of checkbox, but if
you're expecting multiple values, checkbox won't work, you'll only ever see
the final value that the browser submitted.

HTH,
-- 
Wendy Smoak


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


RE: Can html:checkbox take only yes/true/on as value?

Posted by Shilpa Vaidya <sh...@icici-infotech.com>.

Hi prashant

One of my edit pages faced this kinda stufff...

<td align="center"><input type="checkbox" name="siteAdmin1"
onclick="check(document.forms[1].siteAdmin)" <% if (objRole.getSiteAdmin()
!=null && objRole.getSiteAdmin().equalsIgnoreCase("Y")) { %> checked  <%}
else{%> <%}%> value="Y">
     <input type="hidden" name="siteAdmin" <% if (objRole.getSiteAdmin()
!=null && objRole.getSiteAdmin().equalsIgnoreCase("Y")) { %> value="Y" <%}
else{%> value=""<%}%></td>


perhaps this will work as it encloses the check box ...its prepoulated
value...at the same time...a hidden field which sets the new value...incase
we click the checkbox in the edit section.
Shilpa



-----Original Message-----
From: Prashanthi.Pokala@united.com [mailto:Prashanthi.Pokala@united.com]
Sent: Tuesday, July 13, 2004 2:14 AM
To: struts-user@jakarta.apache.org
Subject: Can html:checkbox take only yes/true/on as value?


Hi,



In regular HTML checkbox, the value of the checkbox can practically be
anything. Does the struts html:checkbox limit us to just yes/true/on
values?

If I have a list of records that I get from the database and I want to
display it with a checkbox at the left, the value of the checkbox being
the id of the record, how do I do that? Should there be another hidden
field for the checkbox with the actual value? And how do I connect the
checkbox to its corresponding hidden field?



I have searched high and low and found no clear explanation. I just want
someone to explain this to me.



Also how does the multibox fall into the picture? Can I use checkbox and
multibox interchangeably?

Thanks

Prashanthi



-- 


"This e-mail message may contain confidential, proprietary or legally privileged information. It 
should not be used by anyone who is not the original intended recipient. If you have erroneously 
received this message, please delete it immediately and notify the sender. The recipient 
acknowledges that ICICI Bank or its subsidiaries and associated companies,  (collectively "ICICI 
Group"), are unable to exercise control or ensure or guarantee the integrity of/over the contents of the information contained in e-mail transmissions and further acknowledges that any views 
expressed in this message are those of the individual sender and no binding nature of the message shall be implied or assumed unless the sender does so expressly with due authority of ICICI Group.Before opening any attachments please check them for viruses and defects."