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??
Joined: Oct 24, 2002
Hi, 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. Blair
Joined: Jan 27, 2001
Hi, I tried both things : <type>java.lang.String</type> & <type>boolean</type> but still it give me an error of cant convert String to boolean.
sharp shooter, and author
Joined: May 10, 2000
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. Simon [ December 12, 2002: Message edited by: Simon Brown ]