Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Simple Tag - Sending/Setting an Attribute in the JSP  RSS feed

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have a JSP where I am trying to replace the scripting with EL, Tag Handlers, etc. I have some scripting that checks an ArrayList to see if it is null and if it has more than one element. The attribute name for this ArrayList has been set in an earlier servlet. I am thinking of creating a Simple Tag in the JSP. I know how to get the attribute name of the ArrayList into my tag, but I am not sure how to return a value back to the JSP ? Maybe I am making this more complicated than it needs to be, do I just need to set a variable/attribute in the tag handler code and it will be available to the JSP ? It doesn't have to be anything fancy, a boolean will do.
 
Author and ninkuma
Marshal
Posts: 66806
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never reinvent the wheel. Assuming that the scoped variable's name is myVariable you can check for null or not empty with:

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66806
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But generally, yes, you can create scoped variables in tag handlers.
 
Rod Nichols
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear, I am learning a lot about custom tags and the JSTL. You have been a big help.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!