Java Beginner
Java Beginner

Reputation: 1655

struts generating form elements from bean

I have a Struts 1.2 Bean and a Bean code as below in JSP Page

checkBox.jsp

<logic:iterate property="userList" id="userDet" name="userDetails">
  <html:checkbox property="checked" name="userDet" indexed="true">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>

The above code brings output as below

enter image description here

Now when I submit the form I want to carry out Javascript validation using ids of the checkbox.

How can I generate id for check box generated in JSP page By Bean?Is it possible to generate id attribute dynamically ?

Upvotes: 0

Views: 716

Answers (1)

Sahil Dave
Sahil Dave

Reputation: 353

Try using the 'indexId' attribute (The name of a page scope JSP bean that will contain the current index of the collection on each iteration. ) of

<logic:iterate>

And use it inside the 'styleId' attribute of

<html:checkbox>

Like this:

<logic:iterate property="userList" id="userDet" name="userDetails" indexId="checkBoxIndex">
  <html:checkbox property="checked" name="userDet" indexed="true" styleId="checkBox<%= checkBoxIndex %>">
   <bean:write property="userName" name="userDet"></bean:write>
  </html:checkbox>
</logic:iterate>

Upvotes: 1

Related Questions