Ok I tried, but I got "Failed to obtain specified collection"
Any suggestion please? Fpia
posted 13 years ago
The way you've got it set up, the SelectionAction only runs after the form has already been submitted. You need to have an action that runs before the JSP is displayed so that it can load the list into the ActionForm.
I'd suggest you create a new Action called something like "/prepareSelection" that uses the same ActionForm and forwards to this JSP. Then cut the code that loads the list from the SelectionAction and paste it into this new action. You would then display the page using a URL something like:
Hi! thank you. I understand what you mean. Well, I did that, but now I got:
java.lang.NullPointerException at com.test.struts.users.getUsers(users.java:12)
This means that it is the same problem. The collection is not yet ready. Right? There are no problems in the code or jsp, but how the entities (action, form, jsp) are related among them and the order how they are made. Infact you wrote "The way you've got it set up...". Is there another way to avoid this problem? I mean, in order to have the correct order of the objects definition, do I need to change something in the main structure of my application?
Anyway I'm very surprised, beacuse I learnt a base struts application (like mine) is made of a jsp, a form and an action. Normally it works good! What are the changes I need to do?
Thank you for your suggestions. Fpia
posted 13 years ago
The error that you're currently getting has nothing to do with Struts. It's just a "plain old java error" (POJE?). In your users class (which, by the way should be Users, not users) you try to add to an ArrayList without instantiating it. That's why you're getting a NPE. Change the statment:
and it should work.
Regarding your concept of what a "base struts application" needs, what you say is generally true. However, your application goes a little beyond a "base application" because it has a list of values that needs to be populated before the JSP can be displayed. In this case, you need two actions: one to prepare the JSP, and one to process it once it has been submitted.