WarnerJan Veldhuis wrote:

Here's what I am trying to do:

#foreach ( $object1 in $collection1)
    #foreach ( $object2 in $collection2)
            $actionlink.setParameter("object1", "$object1.id")
            $actionlink.setParameter("object2", "$object2.id")
            <a href="$actionlink.href">$object2.description</a>
   #end
#end

As you can see, the ActionLink is reused in the two iterations. Are you saying that I shouldn't do that? I am happy to move this to the Page class, but I am not sure if I am supposed to create a lot of ActionLinks on the fly like this or reuse the existing one.


Looks fine to me. You can also use a more component oriented approach by creating the ActionLinks in the Page and rendering them in Velocity. It will depend on what is easier for your use case.

If you only want to render a bunch of links, creating a new ActionLinks might be overkill. However if each link can has an associated listener which must be invoked then creating ActionLinks might make more sense.

Btw creating and rendering Click controls are quite fast so I wouldn't worry too much about it. For example, in this performance test[1], Click rendered faster than raw JSP+JSTL.

[1]: http://svn.apache.org/repos/asf/incubator/click/trunk/examples/click-bench/

kind regards

bob

Reply via email to