File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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

chris noe
Greenhorn

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>
or
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
<tag>
<name>if</name>
<tag-class>sampleLib.IfTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>condition</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</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 EVAL_BODY_INCLUDE;
else
return SKIP_BODY;
}
}

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

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
Greenhorn

Joined: Aug 20, 2003
Posts: 14
ok , this makes sense. tnx !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: use of 'type' in the attribute definition of a tld
 
Similar Threads
taglib question
Tag question
Doubts
JSP Custom Tag Lib
Is this a valid tag definition ?