aspose file tools*
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate problem: NullPointerException" Watch "logic:iterate problem: NullPointerException" New topic
Author

logic:iterate problem: NullPointerException

Michele Giunti
Greenhorn

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.
*******************************
CreazioneProfiloUtenteForm.java
*******************************



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.
***********************************
ToCreazioneProfiloUtenteAction.java
***********************************


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.
**************************
creazioneProfiloUtente.jsp
**************************


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.
*****************************************
CaricamentoRuoliAttributiSportAction.java
*****************************************


*********
EXCEPTION
*********


*****************
STRUTS-CONFIG.XML
*****************


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.


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

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.
 
jQuery in Action, 2nd edition
 
subject: logic:iterate problem: NullPointerException