• Post Reply Bookmark Topic Watch Topic
  • New Topic

Posting an Error Message when Custom Tag returns nothing.

 
Michael Arnett
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
Just curious how others resolve this simple issue with minimal mixing of Java and html. For instance, if a custom tag outputs a list of users, how do you output a warning message that no users were found? Its easy to write some html from your EndTag method or to add a scriptlet to your jsp, but is there any way that is more elegant?
Thanks,
-MLA
 
Paul Done
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could follow the example set by the Struts framework with its 'html:errors' tag library tag. Throughout your application you could use the convention of putting warnings into a request atrribute called 'warnings' for example. Then in each JSP, in the place where you would like to show warning messages, use your new tag library tag 'mytags:warnings' which looks at the request 'warning' attribute and prints out its contents into the page, if any exist (if none exist, your tag will output nothing and the page will have no warnings on it).
You could then extend this to enable warning messages to be grouped (eg. 'line item warning', 'page warning', etc) and scoped (eg. page, request, session, application) a bit like Struts can for 'errors'. This would enable you to display different types of warnings in different parts of the JSP page, only when they exist.
Paul
[ January 12, 2003: Message edited by: Paul Done ]
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alternatively, if you're not using the body content, you could use this space as a "default" value like the tags in JSTL do. For example:

Simon
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!