Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use html:checkbox and requestgetParameterValues() in association

 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am tring to access the vlaues that are associated with the checkboxes which are dynamically generatd. The code in the JSP is as follows

<logic:iterate id="array" name="DATA">

<tr>
<bean:write name="array" property="docNumber" /></td>
<bean:write name="array" property="docclassid" /></td>
<bean:write name="array" property="docid" /></td>
<html:checkbox name="documentVerificationForm"
property="checkBox" value=" ??? ">
</html:checkbox>
</td>
</tr>
</logic:iterate>
wheere "documentVerificationForm" is the name of the form "DocumentVerificationForm" in struts config
DATA is an ArrayList and is stoired in request scope and in this arraylist I am stoiring multiple instance of the form bean(documentVerificationForm). Now I want to link the value of the variable docNumber with the text box and access all those docNumber in action class using the code
String docIds [] = request.getParameterValues(???)
so can anybody plzzzz tell me what should be the valus at "?"

Thanks in advance
Samir



 
Shilpa Tendulkar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<logic:iterate name="ApartmentFormBean" id="facility" property="facilityList">
<html:multibox property="selectedFacilities">
<bean:write name="facility" property="id"/>
</html:multibox>
<bean:write name="facility" property="name"/>
</logic:iterate>
I have implemented a similar feature in my application.
Script above displays the list of checkboxes and values selected.
FacilityList is my predefined facility list and selectedFacilities is a string array which contains ids of previously selected facilities.

There could be better way of doing it,I am just a starter in Struts.
 
Shilpa Tendulkar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can retrive in request as follows:
String facilityListing [] = request.getParameterValues("selectedFacilities");
 
Chris Boldon
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure if this is what you're getting at but you must assign a value of whatever you want it to hold if it's checked. If you would like the box to display a 1 when it is checked then 'value = 1'. When the box is not checked it will return a value of 'null'. You must then handle for the null value if if it is going to be stored.

For example, if you are trying to take the value of the checkbox and store it as a boolean then the value = "true". Then you would have to handle



I'm not sure if that's what you were getting at but I hope I could be of some help to you.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
selectedFacilities is a string array

But the specification says the property element of the <html:multibox> should be a type of java.util.Map....
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the specification says the property element of the <html:multibox> should be a type of java.util.Map....

I don't know where you got that idea, but it's incorrect. The property for an <html:multibox> should be a String array.Here is the link to the section of the User guide that describes this tag. Here's a quote from it:

Renders an HTML <input> element of type checkbox, whose "checked" status is initialized based on whether the specified value matches one of the elements of the underlying property's array of current values.
 
samir ware
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are rt Merrill ....I was refering to some local author's book from which I got that information.....And yeah..the way shilpa told me to do the stuff works out....
thanks shilpa for your precious help
thanks to Merrill too for clarification ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic