my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problem from HFSJ book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problem from HFSJ book" Watch "problem from HFSJ book" New topic
Author

problem from HFSJ book

Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

This is problem from book HFSJ (page 507,ch 10)





Above , I have no idea what is 'Movie' and how to set ${movieCollection}?
I am getting annoying Null pointer exception.

I am really curious know to how to pass el as a custom tag attribute?

I hope you understand my problem ,please solve it.

best regards
omi


Back to Java , again.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

movieCollection needs to be a List saved as an attribute of some scope... and that list needs to be full of Movie objects!

I'm not a huge fan of scriptlets, but they can be useful to test something quick and dirty:


Assuming you've got a Movie class out there, this scriptlet should make it work.


A good workman is known by his tools.
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

But Marc I thought Movie is a bean and I did the following with no success.
Where I am wrong? (still get null pointer exception)
Updated code :

[ April 17, 2008: Message edited by: omi sharma ]
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Movie is a bean. Why do you imply that I'm challenging its bean-ness?

Setting movieCollection inside the tag class doesn't make sense. You are supposed to set it before the JSP reaches the simple5 tag so the EL will pass the movieCollection into the tag class using the setMovieList method.

movieList is null. Why are you assuming that it shouldn't be null based on your code?

Then inside the tag you need to set an attribute called movie so that the EL in the tag's body can display it. (Which you have correct near the bottom)
Bobby Sharma
Ranch Hand

Joined: Mar 18, 2008
Posts: 574
    
    1

Originally posted by Marc Peabody:
Movie is a bean. Why do you imply that I'm challenging its bean-ness?

Setting movieCollection inside the tag class doesn't make sense. You are supposed to set it before the JSP reaches the simple5 tag so the EL will pass the movieCollection into the tag class using the setMovieList method.

Then inside the tag you need to set an attribute called movie so that the EL in the tag's body can display it. (Which you have correct near the bottom)


Marc , do you mean I have to set movieCollection inside JSP page
instead of Tag class?

I could not understand the last line(sorry for that),how do I
correct the movie bean? you said I have to correct it near the bottom
what's that mean?

What's Movie inside the Tag class ,I assumed it as a Bean,am I right?

According to the book ,the tag simple6 should iterate movie's values? Please clarify this.

However, your scriptlet solution hit the goal and I solved my problem.
Thanks for that by the way.

But one more question,is there any alternative, because like you I also
hate scriptlet LOL.

best regards,
omi

[ April 18, 2008: Message edited by: omi sharma ]
[ April 18, 2008: Message edited by: omi sharma ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem from HFSJ book