This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Servlets and the fly likes Passing a java.util.Date object to a tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing a java.util.Date object to a tag" Watch "Passing a java.util.Date object to a tag" New topic
Author

Passing a java.util.Date object to a tag

Alok Pota
Ranch Hand

Joined: Mar 07, 2001
Posts: 185
I need to pass a java util.Date object to a tag.
public class Tag1 extends TagSupport {
private Date value = null;
public Date getDate() { return this.value;}
public void setDate(Date value) { this.value = value;}
}
In my JSP I do this..
<page:tag1 value = "<% new Date() %>" />
First the above does not work. Because the "<% %>" converts it to
a String and I have declared the variable as a Date in my Tag.
I need to be able to pass the variable as a Date and declare it
as a Date.
Any ideas
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
have you imported that class from util package. or you can do it like this <page:tag1 value = "<% new java.util.Date() %>" />


Val SCJP <BR>going for SCJD
Alok Pota
Ranch Hand

Joined: Mar 07, 2001
Posts: 185
The import is there. I think the attribute of a tag has to be String. I don't think it can be an Object. In fact the container
Stringfies ceratin objects that you pass to it.
Check this link from Javassoft on Tags.
http://java.sun.com/products/jsp/tutorial/TagLibraries6.html#62006
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Alok,
I think we have to assign script EXPRESSIONS. Not jsp scriplets. A sample code I tested is :

Of course here bgColor can't take a Date value. Some random color will be displayed. But that's ok. It was just a check.
Just put <%= new Date() %> and see!
regds
maha anna
 
GeeCON Prague 2014
 
subject: Passing a java.util.Date object to a tag