Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Custom to tag to retrieve a list of objects?

  Asked By: Kenneth    Date: Sep 23    Category: Java    Views: 693
  

New with custom tags, it's possible to:
Write a custom tag passign an id parameter
The tag searches the database for that id and gets a list of, lets
say, department objects.
If list is empty it should let me to write proper message in the
calling jsp.
If list is not empty, then I should be able to get the list from the jsp.


Is that possible? is there any example?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Aaminah Khan     Answered On: Sep 23

Don't access database  from custom  tags. Pass data you need as a parameter and leave GUI concerns to custom tags.

 
Answer #2    Answered By: Anne Powell     Answered On: Sep 23

yes, it's possible, you should define a tag  with an attribute, say id for your tag.
in your tag class you get that attribute and then build the appropriate query and look up that id from the database. if there is a result, you can loop through the result and write  them to output to be displayed in your page otherwise a message  

your tag class may be extended from IterationTag or you can use SimpleTagSupport

your final tag might be something like this:
<mytag:loadDepartment id="13585" />

 
Didn't find what you were looking for? Find more on Custom to tag to retrieve a list of objects? Or get search suggestion and latest updates.




Tagged: