| Author |
Can I pass a java.util.Date value as an attribute of a tag?
|
Alok Pota
Ranch Hand
Joined: Mar 07, 2001
Posts: 185
|
|
|
<tagname attr="<%= java.util.Date %>"
|
 |
Dale DeMott
Ranch Hand
Joined: Nov 02, 2000
Posts: 514
|
|
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
|
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
|
 |
Alok Pota
Ranch Hand
Joined: Mar 07, 2001
Posts: 185
|
|
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
|
 |
Mike Curwen
Ranch Hand
Joined: Feb 20, 2001
Posts: 3695
|
|
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 ]
|
 |
 |
|
|
subject: Can I pass a java.util.Date value as an attribute of a tag?
|
|
|