• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Handler for tag file

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 40746
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic