Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in value for rtexprvalue element in tld

 
Eshu San
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

In pg 517 under the topic dumb questions :second question's answer says that the rtexprvalue should be marked true if the attribute value is not a string or primitive.Im confused abt this statement..
Consider for ex. the statement below:

<test:myTag attr1=<%=someClass.someMethod()%> />.let us assume that someMethod is returning a string or primitive value.

The tld for the abovetag looks like this:

<tag>
<name>myTag</name>
<tag-class>a.b.someTagHandlerClass</tag-class>
<body-content>empty</body-content>
<attribute>
<name>attr1</name>
<required>true</required>
<rtexpevalue>false</rtexprvalue>
</attribute>
</tag>

The taghandler "someTagHandlerClass" has a attribute setter class whose type is string or a primitive

According to the statement mentioned in the book(i have written it in the first line for reference),if the attribute is not a string or a primitive the rtexprvalue should be set to true.But my example above has attribute that is of type string or primitive .But the value is evaluated at runtime since i have given the value of the attribute as expression.As said in the book ,do i need to put the rtexprvalue element as false coz the attribute type is string or primitive.or do i need to put it as true since the attribute value is evaluated at runtime.

can the author or anybody clarify my confusion

[ November 19, 2004: Message edited by: Eshu San ]

[ November 19, 2004: Message edited by: Eshu San ]
[ November 19, 2004: Message edited by: Eshu San ]
 
Abhishek Mahanty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The sub-element <rtexprvalue> specifies whether the attributeļæ½s value may be dynamically calculated at runtime.

By default the value is
* false for custom tags
* true when used as an attribute of the Tag File "<@attribute ..>" directive

When rtexprvalue is false
--------------------------
The attribute can accept only string literals (which are not evaluated).
These String literals are then converted to the appropriate types as expected by the attribute. e.g. if attribute expects an integer, a literal "20" gets implicitly converted to an integer 20 when assigned to the attribute.

When rtexprvalue is true
--------------------------
The attribute can accept values as
- String literal
- a scriptlet expression,
- an EL Expression or
- by using <jsp:attribute name="attribute_name">value</jsp:attribute> tag.

When passing value as a scriptlet expression, the implicit conversion does not takes place, therefore the expression should evaluate to the type as expected by the attribute.

In your example
<test:myTag attr1=<%=someClass.someMethod()%>
Since you are passing a runtime expression in the form of a scriptlet expression, you should put this in the TLD instead
<rtexpevalue>true</rtexprvalue>
and make sure that the return type of someMethod() is a String. (Otherwise provide the <type></type> element with the attribute's datatype)


Abhi.
[ November 19, 2004: Message edited by: Abhishek Mahanty ]
 
Eshu San
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Are u sure the attribute default value is true in the <%@ attribute ..%> directive of tag file.If that's so then we are forced to provide runtime expressions for the attribute value.I really doubt this.

Can anyone clarify us...
 
Abhishek Mahanty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eshu San:
Hi

Are u sure the attribute default value is true in the <%@ attribute ..%> directive of tag file.If that's so then we are forced to provide runtime expressions for the attribute value.I really doubt this.

Can anyone clarify us...


Yup I am positive about the the default value being true (refre to Table JSP.8-3 of JSP 2.0 specs).

Moreover a value true for rtexprvale doesn't mean that you "must" provide runtime expressions only. Basically it means that the attribute "can" accept run time expressions. So a static literal is valid as well.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic