开发者

Velocity: populating a list with dates from "today" to an arbitratily-set point in the past

I want to populate a drop-down list with months from the current month to a fixed 开发者_如何学JAVAdate in the past using Velocity. I'm not certain if this is possible, since the only loop that is available is foreach and I do not know if there is a sensible way to populate the array the foreach will loop through.

Is this kind of thing simply not something I can do with Velocity? I could achieve it quite easily with Javascript, but for accessibility reasons I'd prefer it to be created by the server.


Yes, this can definitely be done. Check out the DateTool from the VelocityTools project and recall that you can create and populate ArrayLists in VTL:

#set( $arr = [1, 2, 'foo', $bar] )

or

#set( $nums = [1..12] )

or directly:

#foreach( $num in [1..12] )$num #end  ##this is pretty much a for loop

But really, you can also populate the array in java and then drop it into your context. Often that is better than building model data in your view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜