I am working on a Direct to Java Client project and here's the code that the Assistant generates in the user.d2wmodel file when changing the "label" of an attribute.:

{
"class" = "com.webobjects.directtoweb.Rule";
"author" = "100";
"rhs" = {
"class" = "com.webobjects.directtoweb.Assignment";
"value" = "Description";
"keyPath" = "label";
};
"lhs" = {
"class" = "com.webobjects.eocontrol.EOAndQualifier";
"qualifiers" = (
{
"class" = "com.webobjects.eocontrol.EOKeyValueQualifier";
"value" = "billOfMaterialDescription";
"selectorName" = "isEqualTo";
"key" = "propertyKey";
},
{
"class" = "com.webobjects.eocontrol.EOKeyValueQualifier";
"value" = "BillOfMaterial";
"selectorName" = "isEqualTo";
"key" = "entity.name";
},
{
"class" = "com.webobjects.eocontrol.EOKeyValueQualifier";
"value" = "widgetController";
"selectorName" = "isEqualTo";
"key" = "controllerType";
}
);
};
}

In this example, it is the attribute I'm renaming instead of the entity, but it could give you a clue on how to do it for the Entity. The name of the attribute I'm renaming is "billOfMaterialDescription" in the "BillOfMaterial" Entity and I am shortening it to "Description"

You could try removing the first qualifier in the list that is telling it to get the attribute, or simply try "label" instead of "displayNameForEntity".

I'm just guessing here, but since this is the code that the Assistant generates, it is likely a good place to start.

Dave


On Feb 16, 2006, at 11:25 AM, Johan Henselmans wrote:

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,


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
Tel: +31-20-6267538
Fax: +31-20-6273852


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:

This email sent to [EMAIL PROTECTED]

 _______________________________________________
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