aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes doubt in value for rtexprvalue element in tld Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "doubt in value for rtexprvalue element in tld" Watch "doubt in value for rtexprvalue element in tld" New topic
Author

doubt in value for rtexprvalue element in tld

Eshu San
Greenhorn

Joined: Sep 30, 2004
Posts: 18
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

Joined: Jan 26, 2004
Posts: 19
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 ]

SCEA-I, SCBCD 1.3, SCWCD 1.4, SCJP 1.4, OCP
Eshu San
Greenhorn

Joined: Sep 30, 2004
Posts: 18
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

Joined: Jan 26, 2004
Posts: 19
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in value for rtexprvalue element in tld