I have a DirectToWeb application, in which the names that are created for the tables or entities, are not clear for the users, so I have to rename the displayed name. It seems that that is not possible directly, there is no "displayNameForEnity".

I found a mail from 2002 that exactly described my problem,

http://www.wodeveloper.com/omniLists/webobjects-dev/2002/February/ msg00504.html,

where Max Muller describes a solution.

The solution was to extend the Assignment class, and then add a rule to rename the entity in the display.

however, when I tried the code I could not get it to work with the rule engine, apparently I am doing something wrong. Can somebody shed some light?


The rule I tried was with was this one:
======================================================================== ==========
        {
            author = 50;
            class = "com.webobjects.directtoweb.Rule";
            lhs = {
                class = com.webobjects.eocontrol.EOKeyValueQualifier;
                key = "entity.name";
                selectorName = "isEqualTo";
                value = Performance;
            };
            rhs = {
                class = MyDefaultNameAssignment;
                keyPath = displayNameForEntity;
                value = Vorstellung;
            };
        },
======================================================================== ==========




It was fired when I turned on
-D2WTraceRuleFiringEnabled YES

I saw this in the log:

(entity.name = 'Performance') => displayNameForEntity=Vorstellung (java.lang.String) (60001)

The extended class was this one:
======================================================================== ==========
public class MyDefaultNameAssignment extends Assignment {

public static Object decodeWithKeyValueUnarchiver (EOKeyValueUnarchiver eokeyvalueunarchiver) {
         return new MyDefaultNameAssignment(eokeyvalueunarchiver);
     }

     public MyDefaultNameAssignment (EOKeyValueUnarchiver u) {
        super(u);
     }
     public MyDefaultNameAssignment (String key, Object value) {
        super(key,value);
      }

     public Object fire(D2WContext c) {
        String displayName = null;
        if (keyPath().equals("displayNameForEntity"))
displayName = displayNameForKey((String)c.valueForKeyPath ("entity.name"));
        else if (keyPath().equals("displayNameForProperty"))
                displayName = 
displayNameForKey((String)c.valueForKey("propertyKey"));
        else
throw RuntimeException("Attempting to use MyDefaultNameAssignment for unsupported key: " + keyPath());
        return displayName;
     }

    public static String displayNameForKey(String key) {
         StringBuffer finalString = new StringBuffer();
         if (key != null) {
             NSArray keys=NSArray.componentsSeparatedByString(key,".");
             String lastHop=(String)keys.objectAtIndex(keys.count()-1);
             StringBuffer tempString = new StringBuffer();
             char[] originalArray = lastHop.toCharArray();
originalArray[0] = Character.toUpperCase(originalArray [0]);
             Character tempChar = null;
             Character nextChar = null;
             for(int i=0;i<(originalArray.length-1);i++){
                 tempChar = new Character(originalArray[i]);
                 nextChar = new Character(originalArray[i+1]);
                 if(Character.isUpperCase(originalArray[i]) &&
                    Character.isLowerCase(originalArray[i+1])) {
                     finalString.append(tempString);
                     if (i>0) finalString.append(' ');
                     tempString = new StringBuffer();
                 }
                 tempString.append(tempChar.toString());
             }
             finalString.append(tempString);
             finalString.append(nextChar);
         }
         return finalString.toString();
     }
}

======================================================================== ==========

Best Regards,

Johan Henselmans
http://www.netsense.nl
Tel: +31-20-6267538
Fax: +31-20-6273852


Attachment: smime.p7s
Description: S/MIME cryptographic signature

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

This email sent to [email protected]

Reply via email to