Hi Jonathan,
The original aim of the request was to allow a JoSQL statement to be
used directly within Velocity. More specifically it would be that the
WHERE clause, ORDER BY clause and potentially the GROUP BY clause (and
as a further extension the LIMIT and GROUP BY ORDER clauses) could be used.
To do this in Velocity I was going to do (I've written the code but due
to personal reasons not had chance to go further with it yet):
#foreach ($v in $josql.filter ("name LIKE '/opt/%' order by dir, name",
$files))
This isn't as elegant as I'd like but it will work. I had looked at
modifying the Velocity grammar to support N arguments to a tool but I
ran into a number of problems with it. Unfortunately, from what I've
seen, the Velocity grammar has hard coded support for the "foreach"
statement. Personally I'd like to see the grammar in the form:
<tool> [args]
And then have the tool invoked with the arguments passed to it. But
that's not for me to decide.
As for it's implementation in FreeMarker, I would like to do that in
time (I wasn't aware of FreeMarker before), but again having a "native"
implementation for the statement would be preferable to the special
macro you defined. When I get around to a FreeMarker implementation
I'll let you know and you can tell me the possibilities!
Gary
Jonathan Revusky wrote:
Gary Bentley wrote:
Hi,
I'm the developer of JoSQL (http://josql.sf.net) and I've had a
request from a user to extend the foreach directive to include JoSQL
processing facilities.
Along the lines of:
#foreach( $mud in $mudsOnSpecial where $customer.hasPurchased($mud)
order by $mud.price)
<tr>
<td>
$flogger.getPromo( $mud )
</td>
</tr>
Hi, Gary, since you wrote me that note about trying to get in with ASF
(thanks but no thanks) I looked back on your participation in this
list. I see you posed the above question.
Here's how you do the above in FreeMarker:
<#--
Special foreach replacement macro that
sorts the sequence by a fieldname (the orderByField parameter)
and executes the associated nested block if
the condition is satisfied, where the condition parameter
is a function or method that operates on the item in
the sequence and returns a boolean
-->
<#macro specialForeach sequence condition orderByField>
<#list sequence?sort_by(orderByField) as item>
<#if condition(item)>
<#nested item>
</#if>
</#list>
</#macro>
Example usage:
<@specialForeach sequence=mud condition=customer.hasPurchased
orderByField="price" ; item>
<tr>
<td>
${flogger.getPromo(item)}
</td>
</tr>
</@specialForEach>
Now, I didn't have time to look into how you do this in Velocity.
There's a fairly long discussion after this. Could you summarize it?
How do you do the above in Velocity? You can answer in private or on
the list, but really, it should be the latter, since other people
might want to know, and after all, that's what these lists are for,
right?
Cheers,
Jonathan Revusky
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]