This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes taglib attribute type question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "taglib attribute type question" Watch "taglib attribute type question" New topic

taglib attribute type question

Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
Hi everybody, I have a little question regarding the <type> element(subelement of <attribute> in a .tld file. I was wondering what was it used for?
I wrote a tag handler that takes an attribute, so in my tag handler class I have something like this:
note the type of the attribute is int

In my .tld file I have something like this:

and finally, in my .jsp page I have this code that works fine:

At this point everything is normal(to my understanding of course!). I tried to add a <type> element in the .tld file, specifing String as the type for the element like this:

Here I thought the container would try to convert my int variable to a string which would cause a translation time error, but it works fine.
I also tried a couple of different variants like changing the type of the variable used in the jsp expression to String and putting a type of int for the element in the tld file expecting the container to convert the string variable to int, but no... The container takes the variable that is used in the jsp expression and passes it as a parameter to MyIterationTag.setIterations(int).
The <type> element seems to be completelly useless!
Anyway if someone understands this I would really apreciate the help
Thanks in advance
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
Some JSP containers (such as Tomcat) are more lenient than others and often don't take into account the values defined within deployment descriptors. For example, trying changing the body-content of a tag to anything you like!
The type element is just used to give the container a helping hand in determining what the type of the attribute is. Also, some containers may use it to actually restrict the values that can be specified for an attribute, and hence provide some rudimentary validation for you.
In reality, this is one of those elements in the TLD file that is rarely used...
[ January 02, 2003: Message edited by: Simon Brown ]
Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
Thanks for the explanation. I'am indeed using tomcat.

I agree. Here's the link:
subject: taglib attribute type question
It's not a secret anymore!