wood burning stoves*
The moose likes Struts and the fly likes logic:iterate problem: NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate problem: NullPointerException" Watch "logic:iterate problem: NullPointerException" New topic

logic:iterate problem: NullPointerException

Michele Giunti

Joined: Jun 02, 2008
Posts: 12
Hi to all.
I have a problem with a logic:iterate tag. I'm using Struts 1.3.
I have to populate a select with data read from db (by invoking the first Action). When a select option is selected in the jsp, I have to invoke a second Action (on the same jsp page) which has to perform some operations and remember the previous selected option (in the select).
I show you my source code for semplicity.

Here is my ActionForm.

First, the ToCreazioneProfiloUtenteAction action is invoked. This action reads data from db and insert them in the ArrayList 'listaSport'; at the end, this ArrayList is setted in the request.

Then creazioneProfiloUtente.jsp is invoked. I have a select 'sport' that reads the collections in the ArrayList 'listaSport'. Then, I have to store in hidden fields the values of the 'listaSport' arraylist in order to avoid, in the second Action, to re-access to db to read the same values. In order to do so, I use logic:iterate but I have problems with it. I confirm that if I delete from source code the tag logic:iterate, all works well.

This is the second Action, which should be invoked when a select option is selected by user. Unfortunately, this Action is never accessed because I got a java NullPointerException before.



I can't understand where is the problem.
Can you help me?

Thanks to all in advance.

Bye bye.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

I am not really have an experience in Struts framework.

are you using any IDE for the development..
if yes, then use this to debug your code? I think its easy way to find.

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Michele Giunti

Joined: Jun 02, 2008
Posts: 12
I'm using Eclipse.
I had already tried to debug but with no result.
I think the problem is in my ActionForm class but I can't find a solution.

The genereted html is the following:

I think there is a type mismatch between my ActionForm definition ('sport' is a String) and the generated html ('sport' is a org.apache.struts.util.LabelValueBean[]) but I can't understand how to solve the problem.
Tom Rispoli
Ranch Hand

Joined: Aug 29, 2008
Posts: 349
I'm only experienced with struts up to 1.2.7 but I think your problem stems from the fact that this part of your jsp

is set up to generate indexed input fields with the same name as un-indexed property of your form bean. Basically you have a property name "sport" that is a string, but you are setting up hidden input fields that struts will try to put into an array list named sport.

I'm not sure what you're trying to accomplish with this part of your JSP since you are generating hidden fields in your html that don't appear to have any cooresponding properties in your form bean to hold them. If you only need these fields for something on the client side like javascript, just use a different id attribute in your iterate. If you want to keep them so you don't have to look them up again, create a list property in your form bean, populate it with the listaSport values, and use the logic iterate to hide the list on the screen.
I agree. Here's the link: http://aspose.com/file-tools
subject: logic:iterate problem: NullPointerException
Similar Threads
struts action for the root context
Problem running a simple webapplication in struts
Nested Tag (in Form of Table ) :: not able to submit masterForm
Struts 1.3.10 DispatchAction issue