• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can I pass a java.util.Date value as an attribute of a tag?

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<tagname attr="<%= java.util.Date %>"
 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to do that. The code that is in the <% %> brackets will be evaluated first so whatever is written out by the java code should be passed into the tag.
-Dale
 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure? If you look at the Tag tutorial
on JavaSoft and my app server (Resin) also complains
This what the tutorial has to say.
http://java.sun.com/products/jsp/tutorial/TagLibraries6.html#62006

<html>

Tags With Attributes
The start tag of a custom action can contain attributes in the form attr="value". Attributes serve to customize the behavior of a tag just as parameters are used to affect the outcome of executing a method on an object.
Tag attributes can be set from one or more parameters in the request object or from a String constant. The only types of attributes that can be set from request parameter values and String constants are those listed in Table 1; the conversion applied is that shown in the table. When assigning values to indexed attributes the value must be an array; the rules just described apply to the elements.

Table 1 Valid Tag Attribute Assignments
Property Type
Conversion on String Value

boolean or Boolean
As indicated in java.lang.Boolean.valueOf(String)

byte or Byte
As indicated in java.lang.Byte.valueOf(String)

char or Character
As indicated in java.lang.Character.valueOf(String)

double or Double
As indicated in java.lang.Double.valueOf(String)

int or Integer
As indicated in java.lang.Integer.valueOf(String)

float or Float
As indicated in java.lang.Float.valueOf(String)

long or Long
As indicated in java.lang.Long.valueOf(String)


An attribute value of the form <%= scriptlet_expression %> is computed at request time. The value of the expression depends on the type of the attribute's value, which is specified in the object that implements the tag (called a tag handler). Request-time expressions can be assigned to attributes of any type; no automatic conversions will be performed.
The following tag has an attribute named date, which accepts a String value obtained by evaluating the variable today:

<tlt:greeting date="<%= today %>" />
</html>
Notice that
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What that tutorial is talking about is when the attribute is expecting a value of a certain type, and the runtime will automatically convert certain values.

But if you codeWhat should happen is the toString() method of the new Date object will be called, and output to the tag's attribute field.. *before* the tag sees it.

So then it will convert that String into whatever it needs, but hopefully you will have set this attribute up to be expecting a String.

The other thing to make sure of, is that the attribute cannot be given as an expression unless you set it up like that in your TLD.
[ January 28, 2002: Message edited by: Mike Curwen ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic