• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on Tag Handler

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Following Question from Enthuware mock exam.

You are using a tag library with prefix "generator", which supports a tag named "random". This tag generates a
random number and sets it to a variable named "value". Which of the following will output this value in the page?

a.<generator:random><%=value%></generator:random>
b.None of the above.

I selected b. but the answer says a. I think this is wrong if a has to be correct; then in the tag handler the variable should be set as a attribute like pageContext.setAttribute("value",value);.Is that correct?

I did pageContext.setAttribute("value",value); in my tag handler and used
<generator:random>${value}</generator:random> this works fine.but again
<generator:random><%=value%></generator:random> this gives an error saying sriptlet invalid i have proper entries in the TLD JSP and scriptlets are not disabled but still i get this error.

Thanks
 
Vishal Chugh
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raja ,

Sorry to bother you , Could you please check your private message?

Thanks
Vishal Chugh
 
Charles Lyons
Author
Ranch Hand
Posts: 836
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A classic tag can be configured in the TLD (using <variable> ) to also declare and synchronize scripting variables into the JSP page, so they can be accessed using scriptlets or expressions. Since the EL is now in favour, unfortunately I can't find a Web reference for this as all the docs seem to now talk almost exclusively about tag files and SimpleTags, both of which cannot export scripting variables. I explain it fully on pp.418-423 of my book and show example container servlet code from the translated JSPs, but it's just a bit too much to copy/paste here Perhaps someone else can find an example on the Web, or if you have a classic tag you'd like to try we can work out the details... you still export the variable into a scope (e.g. request scope) from your tag handler, then it's just a TLD issue to sort it out.
[ December 06, 2008: Message edited by: Charles Lyons ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic