Re: Velocity Template Question

2009-11-21 Thread Andrew Lindesay
Hi;

Thanks for that -- works really well.

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/archive%40mail-archive.com

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


Re: Velocity Template Question

2009-11-21 Thread Faizel Dakri
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


Re: Velocity Template Question

2009-11-20 Thread Mike Schrag
containsObject is an NSArray method, but these objects are actually Entity 
Modeler's non-WO versions of the EO classes, which are 
java.util.List/java.util.Set, so if it has any chance of working you will need 
to use contains instead containsObject. I've never really tried to do this, 
though, and I don't know what the actual limits of the evaluation engine in 
velocity are. You're also not showing where the "code" variable came from ... 
was that a getEntityNamed("something") assignment earlier?

On Nov 20, 2009, at 3: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/archive%40mail-archive.com

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


Re: Velocity Template Question

2009-11-20 Thread Andrew Lindesay
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/archive%40mail-archive.com

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


Re: Velocity Template Question

2009-11-20 Thread Mike Schrag
i'm not exactly sure what you're trying to do ... are you trying to lookup an 
attribute named "code" and then ask if the given entity contains that 
attribute, then you render whatever is in the #if?  Maybe i should ask you what 
you're attempting to achieve.

On Nov 20, 2009, at 3:17 PM, Andrew Lindesay wrote:

> Hi Mike;
> 
>>> #if ($entity.sortedClassAttributes.containsObject(code))
>> ...
>> and "contains" -- it's a List (maybe a Set). and you would have to have 
>> looked up the attribute "code" already, obviously.
> 
> 
> Sorry; I'm a bit new to this -- can you elaborate on that?
> 
> 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/archive%40mail-archive.com

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


Re: Velocity Template Question

2009-11-20 Thread Andrew Lindesay
Hi Mike;

>> #if ($entity.sortedClassAttributes.containsObject(code))
> ...
> and "contains" -- it's a List (maybe a Set). and you would have to have 
> looked up the attribute "code" already, obviously.


Sorry; I'm a bit new to this -- can you elaborate on that?

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/archive%40mail-archive.com

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


Re: Velocity Template Question

2009-11-20 Thread Mike Schrag
>>> #if ($entity.sortedClassAttributes.code)
> 
>>> #if ($entity.sortedClassAttributes().containsObject(code))
> 
> or
> 
>>> #if ($entity.sortedClassAttributes.containsObject(code))
and "contains" -- it's a List (maybe a Set). and you would have to have looked 
up the attribute "code" already, obviously.

ms
 ___
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


Re: Velocity Template Question

2009-11-19 Thread Chuck Hill


On Nov 19, 2009, at 8:52 PM, Andrew Lindesay wrote:


Hello;

In eo-gen templates, is it possible to do something like this;


#if ($entity.sortedClassAttributes.code)



#if ($entity.sortedClassAttributes().containsObject(code))


or


#if ($entity.sortedClassAttributes.containsObject(code))



should work.


Chuck



...
#end



Where the ... would be inserted if the "code" attribute were present  
in the list of 'sortedClassAttributes'?


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/chill%40global-village.net

This email sent to ch...@global-village.net


--
Chuck Hill Senior Consultant / VP Development

Practical WebObjects - for developers who want to increase their  
overall knowledge of WebObjects or who are trying to solve specific  
problems.

http://www.global-village.net/products/practical_webobjects







___
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