Re: Setting display name for entity in DirectToWeb
Re: Setting display name for entity in DirectToWeb
- Subject: Re: Setting display name for entity in DirectToWeb
- From: Anjo Krank <email@hidden>
- Date: Thu, 16 Feb 2006 13:05:56 +0100
Instead of putting this in the d2w rules, you're probably easier off
to add this in the entity's userInfo in EOModeler. But anyway: the
value will only get picked up if you use templates that use it.
Project Wonder has some, but you could also just dump the ones in D2W
and extend them.
Cheers, Anjo
Am 16.02.2006 um 12:25 schrieb Johan Henselmans:
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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40logicunited.com
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