You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by James Wang <to...@yahoo.com> on 2002/08/22 11:39:08 UTC

how to compare the time in Velocity?

I wrote a porlet to show some news from my database,
some news are new and some are old,for example,i
create a news record,and
set a Timestamp field 'expired_time' to indict its
expired date,
and then I retrieve all news from the database

...
String sql = "select news_id,news_title,expired_time
from newsdatabase"

java.sql.ResultSet rs = st.executeQuery(sql);

java.util.Hashtable allNews = new
java.util.Hashtable();

NewsItem  newsitem =  new NewsItem();
String newsid;

while(rs.next){
   newsitem.setNewsId(Integer.parseInt(newsid));
   newsitem.setNewsTitle(rs.getString(2));
   newsitem.setExpiredTime(rs.getDate(3));
   allNews.put(newsid,newsitem);
}   

context.put("allnews",allNews);
...

in my velocity template file,i want to show all the
news data from 'allNews'
but i want only the news whose expired time is before
the current date for normal
users,but for news editor,i want to show all news to
them,so i have to judge the
expired time of the every news.i can get the expired
date with
  
  $allnews.get($key).getExpireTime()

but how i can compare it with current date in
Velocity,it seems that only thins
which can compare is string,integer,but not
date,time!!!
...
#foreach( $key in $allnews.keySet())
  #if($allnews.get($key).getExpireTime()< currentDate)
    show
  #else
    not show  
  #end
#end

how can deal with this?
as now,i am missing JSP,in JSP,i can write java code
to compare the date,but 
with Velocity,nothing can do!? i have to write some
code in my porlet code?
but i want to keep the portlet code simple, and i
think such thing
(i mean,compare the date) should be done in Velocity
template.

Maybe i am not familiar with MVC style in
Turbine/Jetspeed/Velocity.:(

anyone can help me? thank u very much first.




__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>