This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "attribute for custom tags" Watch "attribute for custom tags" New topic
Author

attribute for custom tags

Christopher Au
Greenhorn

Joined: Jul 26, 2007
Posts: 21
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

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
Greenhorn

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)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: attribute for custom tags