File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Regarding rtexprvalue 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 "Regarding rtexprvalue" Watch "Regarding rtexprvalue" New topic

Regarding rtexprvalue

Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Hi! Am a little confused about the rtexprvalue element.
If I have a boolean b=false;
String s="true";
using taglib:
<%@ taglib uri="someuri" prefix="p" %>
<p:someTag booleanValue="<%=s%>" />
In the tld the rtexprvalue is set to true/yes.
But the above code gives me a compile time error.
If the code is modified to :
<p:someTag booleanValue="<%=b%>" /> then it works fine.
Will someone plz explain to me what is exactly the rtexprvalue??
blair cairns

Joined: Oct 24, 2002
Posts: 8
The <rtexprvalue> is the run-time expression value, namely whether the attribute value can be read from a jsp expression or not. If this is set to true then the default return type for the expression is java.lang.String, but if you look at your tld, you will probably see an element called <type> underneath the <rtexprvalue> which stipulates that it is a boolean. If not, then I am just as baffled.
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
I tried both things :
but still it give me an error of cant convert String to boolean.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
I actually used this exact same example in my book about how rtexprvalues work. If you write the setter method on your tag handler as "public void setX(boolean b)", then you have two options for using it.
(1) You can use a static string like "true" (e.g. <myTag X="true"/>) and the JSP container will automatically convert this value for you. In fact, the container will also convert strings to numbers too.
(2) You can use a rt expression (e.g. <myTag X="<%= b %>"/>)
The real difference between (1) and (2) is that the container doesn't automatically convert the values of rt expressions. Therefore, if you do use an rt expression, the result of evaluating it must be of the same type as that declared in your setter method. This means, with your example, that you can't use <%= s %> as it evaluates to a string value which cannot be cast to a boolean.
The rule to remember here is that automatic conversion only happens for non-rt values.
Hope that helps.
[ December 12, 2002: Message edited by: Simon Brown ]
Atul Darne
Ranch Hand

Joined: Jul 05, 2009
Posts: 118

After providing the setter for the variable

you can use the following syntax which takes bool as string and will parse for you (it doesnt have any errors too)

In the java code

setter Tag


in the TLD



Regards, Atul.
I came to this world on a Learner's License
I agree. Here's the link:
subject: Regarding rtexprvalue
It's not a secret anymore!