This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes unable to initialize a list from custom simple tag handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "unable to initialize a list from custom simple tag handler" Watch "unable to initialize a list from custom simple tag handler" New topic
Author

unable to initialize a list from custom simple tag handler

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
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: 119
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: 119
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to initialize a list from custom simple tag handler
 
Similar Threads
Custom Tag Attribute problem
Tag attributes and the setter method
Simple Tag with Attribute
problem from HFSJ book
Doubt in HFSJ..pg 511 creating simple tag with attribute