permaculture playing cards
The moose likes Struts and the fly likes html:multibox... + validation == No collection found 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 "html:multibox... + validation == No collection found" Watch "html:multibox... + validation == No collection found" New topic

html:multibox... + validation == No collection found

Mikael Vedek

Joined: Nov 18, 2005
Posts: 1

i've been struggling with this problem whole day and thought that someone of you gurus could help me.

The problem is <html:multibox and validating results which leads to javax.servlet.ServletException: No collection found.

In the action I populate the actionForm with LabelValueBeans

And in the ActionForm I have

and in the view (.jsp)

Everything works just perfect IF the other fields of the form are valid but if there's something caught by ActionErrors validate()-method I get:

javax.servlet.ServletException: No collection found

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

- Mikael
Frank VanOor
Ranch Hand

Joined: Jun 18, 2004
Posts: 49
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.

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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:


If this value is null, create it from the database and place it in the servletContext.

Then modify your <logic:iterate> tag so that name="possibleOptions" and there is no properties attribute. Struts will then find the object in application scope.

This is more efficient as it avoids going to the database over and over again to retrieve the same data. This will not work, however, if the possible options are not the same for every user.

Consultant, Sima Solutions
I agree. Here's the link:
subject: html:multibox... + validation == No collection found
It's not a secret anymore!