aspose file tools*
The moose likes Struts and the fly likes html:select problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:select problem" Watch "html:select problem" New topic
Author

html:select problem

Fabrizio Pia
Greenhorn

Joined: Apr 24, 2007
Posts: 10
Hello. I'm trying to make a menu selection with struts 1.1 but I get the message "Property list returned a null value".
Please, where is the problem??

Here the code:


--------SelectionForm.java-------------



-----------SelectionAction.java---------------



I write also my Model code:

------users.java-----



Here my struts-config.xml file:


About html ption tag, I also tried with the collection attribute, but I got the message "Cannot find bean under name list".

Can anyone help me please? I'm spending too many days on this problem!!

Thank you in advance.

fpia
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Change:

to:


Merrill
Consultant, Sima Solutions
Fabrizio Pia
Greenhorn

Joined: Apr 24, 2007
Posts: 10
Ok I tried, but I got
"Failed to obtain specified collection"

Any suggestion please?
Fpia
Merrill Higginson
Ranch Hand

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

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

Can you help me please?
Thank you

Fpia
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Please read carefully my previous post dated Tuesday, April 24, 2007 1:09 PM
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: html:select problem