Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to define multiple tag handlers

 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I just tried to execute the example(Menu and MenuItem tag handlers) given on the page 543 in HFSJ first editon.

There two tag handlers are given:Menu and MenuItem..
But how to define these tag handlers in Tag Library Descriptor..Should i use seperate TLD for seperate tag handlers or only in one file should i give the both tag handlers..

Any link which provides how to deal with multiple tag handlers is of great help as these things are not explained in HFSJ

Thanks & Regards,
Sudhakar Karnati
 
Shikhar Madhok
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this link

I think the general convention is one tld file per-prefix.
So say you define multiple tags specifically for menus then you would have one menu.tld and within it you would have definition for say mainMenu tag and subMenu tag and the usage in the jsp would be like menu:mainMenu or menu:subMenu.
If your application is not that big then you can have just a single tld file which would define all the custom tags in your application.

HTH
Shikhar
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should i use seperate TLD for seperate tag handlers or only in one file should i give the both tag handlers..

You can do both. If you use different TLDs, you'll also have to use different prefixes in your JSP. If you use only one TLD, yoう can use multiple <tag> tags in it.
[ July 09, 2008: Message edited by: Christophe Verre ]
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do both. If you use different TLDs, you'll also have to use different prefixes in your JSP. If you use only one TLD, yoう can use multiple <tag> tags in it.


I tried this but not getting the result:

Here is my code:

index.jsp


Simple.tld


Simple1.tld


Menu.java


MenuItem.java


Please tell me what is wrong in the above code..

Thanks & Regards,
Sudhakar Karnati
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the parent's body content set to "tagdependent", I don't think that the inner tags will be evaluated. But there's a bigger problem : Menu's doEndTag is not spelled properly. doEndtag -> doEndTag
[ July 10, 2008: Message edited by: Christophe Verre ]
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Change:
<short-name>simple</short-name> in simple.tld
to
[bhort-name>Menu</short-name> [/b]
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore my above post and consider this:
Change:
<short-name>simple</short-name> in simple.tld
to
<short-name>Menu</short-name>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anand, the short-name has no influence on the way the tag will be used.
 
sudhakar karnati
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the parent's body content set to "tagdependent", I don't think that the inner tags will be evaluated. But there's a bigger problem : Menu's doEndTag is not spelled properly. doEndtag -> doEndTag


I made the aove changes(tagdependent to scriptless) and it is working fine..
Thanks for your quick replies..

Thanks & Regards,
Sudhakar Karnati
 
Anand Bhatt
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christophe , I was confused <short-name> with <name>.
You are correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic