• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retriving values from html:checkbox in a jsp

 
skumar mk
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai All,

Am facing a problem to retrive the values from the <html:chechbox>
Am using code like this:

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<body>
<html:form action="/log" method ="post">
<table width="500" border="0">
<tr>
<td>username :</td>
<td><html:text property="username" /></td>
</tr>
<tr>
<td>password : <br><br></td>
<td><html assword property="password" /><br><br></td>
</tr>
<tr>
<td><html:submit property="login" value="ADD"></td>
</tr>
</table>
<logic resent name="LIST_ELEMENTS" scope="request">

<logic:iterate id="myvalues" name="LIST_ELEMENTS">

<html:checkbox property="ck_values" >

<bean:write name="myvalues" />

</html:checkbox>

</logic:iterate>
</logic resent>

</html:form>

</body>
</html:html>


In the action class am setting the values ArrayList and storing it in the request scope

java.util.ArrayList list = new java.util.ArrayList();
list.add(vmarks);
list.add(vid);
request.setAttribute("LIST_ELEMENTS",list);

I need the values selected from the checkbox (vmarks,vid). when am using request.getString("ck_values") am getting ON then how can i retrive the slected values in my action class.


Please help me out.


Thanks in advance
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use html:multibox instead of html:checkbox. It still produces checkboxes, but is designed to be used with a group of related checkboxes all with the same property name. Below is the link to do documentation.

http://struts.apache.org/1.3.8/struts-taglib/tlddoc/html/multibox.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic