Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing a java.util.Date object to a tag

 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you imported that class from util package. or you can do it like this <page:tag1 value = "<% new java.util.Date() %>" />
 
Alok Pota
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic