This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes use of 'type' in the attribute definition of a tld Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "use of Watch "use of New topic

use of 'type' in the attribute definition of a tld

chris noe

Joined: Aug 20, 2003
Posts: 14
Hello, I've copied the exampel beneath from 'SCWCD exam study kit second edition' (Manning)
We try to pass a boolean to the tag class.
In the 'attribute' definition, no <type> is given, so the class expects the default, being a String.
Altough , the setCondition expects a boolean as parameter.
That leaves us with 2 possibilities :
1. they forgot the <type> attribuut in the defintion of the attribute and it should say : <type>boolean</type>
2. "<%= debug %>" returns a String and the tag class does the conversion to boolean before the setCondition is called.

If 2 is correct, what's the use of <type> than ?

definition of the tag

code of the tag class
public class IfTag implements Tag
//other methods as before
private boolean condition = false;
public void setCondition(boolean condition)
this.condition = condition;

public int doStartTag() throws JspException
if (condition)
return SKIP_BODY;

jsp code
<%@ taglib prefix="test" uri="/WEB-INF/sampleLib.tld" %>
<% boolean debug = "true".equals(request.getParameter("debug")); %>
<test:if condition="<%= debug %>" >

pls help, as my exam is comming up
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
JSTL expression can make implicit type coercion. But what, if you want to pass some user type. Than the <type> element will be necessary. Isn't it?
chris noe

Joined: Aug 20, 2003
Posts: 14
ok , this makes sense. tnx !
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: use of 'type' in the attribute definition of a tld
It's not a secret anymore!