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:

Fabrizio Pia
Greenhorn

Joined: Apr 24, 2007
Posts: 10

posted Apr 26, 2007 01:35:00

0

Hi! thank you. I understand what you mean. Well, I did that, but now I got:

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

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864

posted Apr 26, 2007 07:57:00

0

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:

to

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.

Fabrizio Pia
Greenhorn

Joined: Apr 24, 2007
Posts: 10

posted Apr 26, 2007 11:13:00

0

Ops! Yes you're right! Now it works.

But anyway the LabelValueBean does a very strange effect...

Now my code is

The menu should have three options "Mr. White", "Mr...", while in my menu I see "LabelValueBean[Mr. White,1]", then as second option "LabelValueBean[Mr. Gree, 2]"...

The add method takes the "new" argument as a string nut the code should be correct!! Do I need to change the html ption configuration?