• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

attribute for custom tags

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am writing some custom tags at the moment and I was wondering instead of passing strings and integers as attributes to this custom tag. Is it possible to pass an Object to the custom tag. From what I have read it seems to be possible but when I tried it Eclipse was not too happy about it. I am using jstl 1.1

Thanks
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Christopher Au:
Eclipse was not too happy about it.


Can you elaborate on that?

Also, are you talking about custom tags or JSTL?
Custom tags are tags that you make yourself.

In either case, yes, you can pass objects to your tags via tag attributes.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. You can pass object to the tag.

I am using JSP2.0 tag and following is what you can do.

Let's say you want to format address at more than one pages in your web application. So you are creating a formatAddress.tag which is re-usable.You will simply pass your address object and the tag will format it.(i.e Label, Adress line 1 , Address line 2 ,... )

Following is the code snippet for formatAddress.tag,look at the attribute specified.

<%@ tag description = "Outputs an address object in the correct format." pageEncoding="UTF-8"%>

<%@ attribute name="address" required="true" type="uk.co.fresca.pojo.Address"%>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

//your custom logic to play with address format.


The caller of this tag would be
<xyz:formatAddress address="${addressPojo}"/>

Here xyz , is your taglib prefix.

Hope that helps.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic