You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Carl Walker <wa...@georgetown.edu> on 2003/05/30 13:11:34 UTC
Re: Checkbox
You should use a java.lang.String or java.lang.String[] property if you want
to have 'abc' submitted when checkbox 'chk' is checked.
If you want 'true' to be sent when 'chk' is checked, then change 'abc' to
'true'.
Take a look at this example for additional guidance
<%-- FILE checkForm.jsp --%>
<%@ taglib prefix="html" uri="/WEB-INF/struts-html.tld" %>
<html:html>
<body>
<h1>checkForm</h1>
<html:form action="/check.do">
<p>Do you like soda?</p>
<html:checkbox property="likesSoda" value="true">Yes</html:checkbox><br>
<p>If you like soda (or were forced to drink one) what would you drink?</p>
<html:checkbox property="sodas" value="coke">Coke</html:checkbox><br>
<html:checkbox property="sodas" value="pepsi">Pepsi</html:checkbox><br>
<html:checkbox property="sodas" value="7-up">7-up</html:checkbox><br>
<html:submit value="Submit" />
</html:form>
</body>
</html:html>
<%-- END FILE checkForm.jsp --%>
<%-- FILE check.jsp --%>
<%@ page import="java.util.*" %>
<%@ taglib prefix="logic" uri="/WEB-INF/struts-logic.tld" %>
<%@ taglib prefix="bean" uri="/WEB-INF/struts-bean.tld" %>
<html>
<body>
<h1>check</h1>
<bean:define id="likesSoda" name="SodaForm" property="likesSoda" />
<p>Likes soda?: <bean:write name="likesSoda" /></p>
<p>Preferred sodas:</p>
<bean:define id="sodas" name="SodaForm" property="sodas" />
<logic:iterate id="soda" name="sodas">
<bean:write name="soda" /><br>
</logic:iterate>
</ul>
</body>
</html>
<%-- END FILE check.jsp --%>
Put these in your struts-config.xml (in the appropriate sections).
<form-bean name="SodaForm"
type="org.apache.struts.action.DynaActionForm">
<form-property name="likesSoda" type="java.lang.Boolean"
initial="false"/>
<form-property name="sodas" type="java.lang.String[]" />
</form-bean>
<action path="/checkForm" forward="/checkForm.jsp" />
<action path="/check"
name="SodaForm"
scope="request"
forward="/check.jsp" />
FILE
"Abhinav (Cognizant)" wrote:
> This one is not getting into my head ..
> <html:checkbox property="chk" value="abc" />
> and in the form bean
> boolean getChk(), void setChk(boolean)
> checkbox is checked and form is submitted.
> how do I retreieve the value "abc"
>
> Thanx.
>
> ------------------------------------------------------------------------
> Name: InterScan_SafeStamp.txt
> InterScan_SafeStamp.txt Type: Plain Text (text/plain)
> Encoding: 7bit
>
> Name: InterScan_Disclaimer.txt
> InterScan_Disclaimer.txt Type: Plain Text (text/plain)
> Encoding: 7bit
>
> ------------------------------------------------------------------------
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org