• Post Reply Bookmark Topic Watch Topic
  • New Topic

Handler for tag file  RSS feed

 
Med Ouali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

favorite
I am using tag file to make a layout for all my page.

In this layout there are same information that needed to be imported from the database. I want to create a class handler for /WEB-INF/tags/file.tag that is responsible for all the logic and associate the result to an attribute like between controller and jsp.

How can I create this class and associated to the tag file.

I need a method in this class to be executed and pass the necessaries attributes to my tag file.


Is it possible to include a SimpleTagSupport class in my tag-file so that it can handle the process of the variable(get them from the database) and then use this variable in my tag-file.

Is there any other solution that does not involve using a view engine

what I want is to create a template for all my pages and inject fragment in this template. The template should load some data from the database (notification data in the menu that is in the template file).

Thank you very much.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Med,
Welcome to CodeRanch!

Your tag file shouldn't be accessing the database. Just like JSPs shouldn't access the database, neither should tag files - they are still view.

Instead create a servlet filter to access the database and put the relevant data in the request/session. Then your tag file just has to read and render them.
 
Med Ouali
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

if I create a servlet filter can I specify that the it will execute only when the tag layout file is loaded.

Explication:
if I have two layout and I need to load different data for each layout can I specify tow servlet filter for each one?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh You said "each page" so I thought all the pages have the same data.

How do you tell which data to load for which page? If controlled by URL, you could map this with an if statement in the servlet filter.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!