Let's say I have a JavaBean that remembers a user's checkbox selection:

<input type="checkbox" name="isMale" value="true" <%=bean.isMale () ?
"checked" : ""%>>

i.e. when the page is reloaded the checkbox is correctly shown selected or
not.
Here's my attempt at setting this value to true or false:

<jsp:setProperty name="bean" property="isMalet"
value="<%=request.getParameter (\"isMale\") != null%>" />

Remember that a user may want to change from true to false or visa versa. Is
there a more efficient way of doing this?
Checkboxes have the obvious problem of not passing the field name in the
request if unselected.
If I used the above method, then I'd have to beware of any other JSP pages
that get redirected to this page.

In the meantime, I'll use 2 radio buttons that are have the values true or
false, to forcibly pass a value!

<jsp:setProperty name="bean" property="*" />
<input type=radio name="isMale" value="true" <%=search.isMale () ? "checked"
: ""%>>Yes
<input type=radio name="isMale" value="false" <%=search.isMale () ? "" :
"checked"%>>No

Kane Marshall

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to