• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Regarding rtexprvalue  RSS feed

 
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??
 
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.
 
sharp shooter, and author
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 ]
 
Ranch Hand
Posts: 119
Java Opera 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!