wood burning stoves
The moose likes JSP and the fly likes attribute for custom tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "attribute for custom tags" Watch "attribute for custom tags" New topic

attribute for custom tags

Christopher Au

Joined: Jul 26, 2007
Posts: 21

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

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

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.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
vishalraju shah

Joined: Oct 06, 2007
Posts: 19
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.

SCJP1.4 (92%), SCWCD (85%), SCBCD (81%), SCEA-I (In Progress)
I agree. Here's the link: http://aspose.com/file-tools
subject: attribute for custom tags
It's not a secret anymore!