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      (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/webobjects-dev/listfez%40dakri.com
> 
> This email sent to list...@dakri.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to