• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tag attributes and the setter method

 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the "Simple tag with attribute" example on page 511 of HFSJ working.

Here's the code . . .


The tag handler class and the bean are in $CATALINA_HOME/webapps/simple_tag/WEB-INF/classes/foo.

The .tld is in /WEB-INF.

When I run it, in Tomcat 5.5.12, I get a NullPointer exception at the line where the iterator is declared in the tag handler.

Any thoughts will be greatly appreciated.

Thank you,
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Two big things here.
1) I don't think movieCollection.add("${movie1}"); will work because I don't think EL works inside of scriptlets.

2) <myTags:movieTag movieList="${movieCollection}"> won't find your collection because your never added it to any scope. Try ending the scriptlet with a:
request.setAttribute("movieCollection", movieCollection);
Fixing this second part alone will solve the NullPointer.
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two big things here.
1) I don't think movieCollection.add("${movie1}"); will work because I don't think EL works inside of scriptlets.

2) <myTags:movieTag movieList="${movieCollection}"> won't find your collection because your never added it to any scope. Try ending the scriptlet with a:
request.setAttribute("movieCollection", movieCollection);
Fixing this second part alone will solve the NullPointer.


I guess these should not be a problem.

Micheal,

I have given it a try but with no luck. I used



SimpleTagSupport to implement DynamicAttributes and also tried to add <dynamic-attributes> in tld. It was mentioned in HFJS on pg562 Q7. Try using this, may be it would solve your problem. Please let me know if you solve it.

Thanks
Chandu
 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this works . . .



Thanks for the tip Marc.
No telling when it would have occured to me to give the thing a scope.
[ March 03, 2006: Message edited by: Michael Clark ]
 
Chandra Sagi
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marc,

No offense. You are correct. Could any of you explain me about Question 7 in HFJS on pg562.

Thanks in Advance.
Chandu
 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't get to dynamic att's yet, Chandu.

Did you read Bryan Basham's tutorial?:

http://www.coderanch.com/t/170429/java-Web-Component-SCWCD/certification/Tutorial-Dynamic-Attributes
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic