Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

attribute for custom tags

 
Christopher Au
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
vishalraju shah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic