Re: Velocity Template Question
Re: Velocity Template Question
- Subject: Re: Velocity Template Question
- From: Faizel Dakri <email@hidden>
- Date: Sat, 21 Nov 2009 10:25:37 -0600
I'm assuming that the 'code' is an EO attribute of an entity. I think you'll have to iterate over the list of attributes, check the name and set a flag manually. Then you can conditionally generate your template code base on the flag.
I may be wrong--and I'd love to find an easier way if I am--but this is how I do such a thing in my templates. I haven't actually tested the following code, but I use something similar to check for the presence of not-null class properties. Maybe it will point you in the right direction:
#set ($hasCode = 'false')
#foreach ($attribute in $entity.classAttributes)#if ($attribute.name == 'code')#set ($hasCode = 'true')#end#end
#if ($hasCode == 'true')
@SuppressWarnings("unchecked")
public static nz.co.orcon.osm.eo.main.OcnDuration fetchByCode(EOEditingContext ec, String code) {
....
}
...
#end
I haven't yet found an easy way to break out of the foreach loop, so for now my templates always iterate over the entire list of attributes (but only once to set the flag).
Hope that helps.
Fez
On 2009-Nov-20, at 02:46 PM, Andrew Lindesay wrote:
> Hi Mike;
>
> You are right; I'm trying to add a method to the entitys' superclasses for fetching based on "code" if the "code" attribute is present. I'm trying to achieve what I had before using velocity. I am doing something like this, but the #if is not firing;
>
>> #if ($entity.sortedClassAttributes.containsObject(code))
>> @SuppressWarnings("unchecked")
>> public static nz.co.orcon.osm.eo.main.OcnDuration fetchByCode(EOEditingContext ec, String code) {
>> ....
>> }
>>
>> ...
>>
>> #end
>
> cheers.
>
> ___
> Andrew Lindesay
> www.lindesay.co.nz
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden