Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding rtexprvalue

 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vedhas Pitkar
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Atul Darne
Ranch Hand
Posts: 118
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


Usage


in the TLD



JSP Tag



Usage
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic