This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
If I understand correctly this is due to the fact that the collection is not anymore in the request, right? If I create a constructor for the ActionForm with some static LabelValueBeans the validation works just fine.
Any ideas how to proceed?
P.S: Yes, I know accessing DB directly from the action is a bad thing. I will learn to use Hibernate as soon as I have some spare time
The "No collection found" message comes from the JSP. It means that the collection holding all available checkboxes is empty. But, how did it become empty ? It becomes empty by the validate method. So, when the validate method returns ActionErrors, the JSP is re-displayed. But this time, the collection of available checkboxes is empty or null and you'll see the "No collection found" error message.
solution: When the validate method creates ActionError objects, make sure you populate the collection of available checkboxes before the validate method exits.
Frank's solution will work, but if you're going to re-create the possible options, I prefer to do it by overriding the reset() method in the Actionform and placing the logic there. This always gets called before validate() and it seems cleaner to put the rebuild logic there and save the validate() method only for validation logic.
There is also another solution: If you think about it, the possible options are probably the same, no matter who is calling the page, right? If this is the case, why not just build this array of options once and store it in application scope? In my opinion, the best solution would be to modify the logic in your action to check for the existence of the array like this: