File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation" Watch "Validation" New topic


Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
I am reading data from database and display it with a checkbox. So number of checkboxes are dynamic, I could have 1 to n check boxes.
I want the user to check all of the boxes before submitting the form.
Question: In validation how to validate that all boxes are checked, since number of boxes are dynamic?

My JSP page

Thank you in advance
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
i hate to say this up front, but why have checkboxes if they're gonna be checked anyway? can't you display a fake 'checked' images and keep the values in a hidden field?
<p />
in any case, you'll need to do custom validation.
1. pass the number of items into a hidden field (you can use the varStatus attribute of the c:forEach tag to keep a counter, or have it passed to the page in the request, or set it in the action using form.set("hiddenFieldName",checkboxCollectionCount)).

2. add a custom validation method to check the number of checkboxes checked agains the value in the hidden field (see this link - validateTwoFields example for how to set up custom validation -

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: Validation
jQuery in Action, 3rd edition