| Author |
unable to initialize a list from custom simple tag handler
|
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
|
|
I have a class called Movie looks like
Then I have a another class called SimpleTagTest5 which is basically a tag handler looks like
The tld file and the way it is invoked in index.jsp file looks like as follows
simple.tld
index.jsp:
It is giving me NullPointerException because i have not initialized ${movieCollections}. How to make this program work. I wrote the scriplet code in index.jsp initializing ${movieCollections}, bu still it didn't work. Code is also not complete in the book (head first Servlets and JSP).
The exact error message is
Where is the problem?
regards
Anil Deshpande
|
Anil Deshpande
SCJP 1.5, SCWCD 1.5
|
 |
Michael Schlegel
Greenhorn
Joined: Sep 11, 2009
Posts: 13
|
|
Hi,
1.) I would say, you should check if field movieList is null or not.
2.) What is correct ${movieCollections} or ${movieCollection}? I ask this, because you used this to different names in code and discription.
How did you initialized movieCollection?
|
 |
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
|
|
it is ${movieCollection} not ${movieCollections}
And I did changes in the code to check if the movieList is null. It is null as expected. If I want to initialize it what and how it can be done?
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
And I did changes in the code to check if the movieList is null. It is null as expected. If I want to initialize it what and how it can be done?
Preferably in servlet ,
1)create Movie bean object using setters ,
2) Add to a list say movieList.
3) repeat above steps if you want to add more than 1 movie.
4) Make the movieList (list) available as attribute in session scope as "movieCollection"
5) forward your request to JSP using RequesDispatcher
|
 |
Michael Schlegel
Greenhorn
Joined: Sep 11, 2009
Posts: 13
|
|
Hi,
the simplest way to do this is to write a little peace of java code inside jsp:
Note: this is not a clean way.
Normally you should init movieCollection inside a controller (e.g servlet) and put them into the current used session or the request.
|
 |
Balu Sadhasivam
Ranch Hand
Joined: Jan 01, 2009
Posts: 874
|
|
the simplest way to do this is to write a little peace of java code inside jsp:
Neither preach , nor practice.
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
Hey,
I would just like to say your tag is pretty much exactly the same as the <c:forEach> tag from the JSTL (only it will only work with your specific type of list).
|
I love this place!
|
 |
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
|
|
|
I did the changes in the index.jsp to include a scriplet code to initialize movieCollection. It is working fine now. Thanks a lot. Everybody I appreciate replies.
|
 |
 |
|
|
subject: unable to initialize a list from custom simple tag handler
|
|
|