If you are not familiar with WOnder enough, here is another solution to the problem.

We use .strings files (see WOResourceManager for localization) and prefix the number with a constant.
It end up like :
 {
        Status_0 = "stopped";
        Status_1 = "running";
...
}

We overwrite KVC at the component level to understant WOString binding like :
{ value = @translateValueWithPrefix$Status_$myEOItem.status; }
A binding like this one will then invoke : translateValueWithPrefix("$Status_$myEOItem.status");

Assumin that myEOItem is an enterprise object that return a Integer when asked 'status()'.

The following are generic WOComponent methods (implemented in your root wocomponent subclass).

    /**
         * This method resolve kvc in a localizable.strings file.
* Ex : @translateValueWithPrefix.FrameworkName$FileName$Prefix$key.path
     * @param   kvc key path information to be localized.
         * @return      String comming from the localizable.strings file.
     */
public String translateValueWithPrefix(String kvc) {
                String separator = "\\$";
                String strs[] = cle.split(separator);
                String frameworkName = frameworkName();
                String fileName = "Localizable";
                String prefix = "";
                String keyPath = "";
                if (strs.length == 1) {
                        keyPath = strs[0]; // hmmm ... we forgot to give a 
prefix
                } else if (strs.length == 2) {
                        prefix = strs[0];
                        keyPath = strs[1];
                } else if (strs.length == 3) {
                        nomFichier = strs[0];
                        prefix = strs[1];
                        keyPath = strs[2];
                } else if (strs.length == 4) {
                        frameworkName = strs[0];
                        nomFichier = strs[1];
                        prefix = strs[2];
                        keyPath = strs[3];
                }
return translateKey(frameworkName, nomFichier, prefix+String.valueOf((valueForKeyPath(keyPath))));
        }

public String translateKey( String frameworkName, String fileStr, String aKeyString ) { return (aKeyString == null) ? null : application().resourceManager().stringForKey(aKeyString, fileStr, aKeyString, frameworkName, langues());
    }

- jfv

Le 06-08-06, à 11:52, Q a écrit :

I am currently reimplementing parts of an existing legacy web application using WO as a learning exercise (I'm a WO newbie), and have been trying both D2W and regular components. One issue I have encountered with the database I am using is that it uses quite a number of integer fields to represent properties that map to strings when presented to the user. However this mapping is not present in the database, only the legacy application's interface code. (I am not able to modify the database schema)

After playing with D2W for a bit and creating a couple of custom components that were virtually identical it occurred to me that this mapping data doesn't really belong in a custom component, instead it should actually be in the eomodel. So I wrote a custom D2W component to map the integer value to the appropriate display string using some custom keys in the attribute's userinfo dictionary from the eomodel. This appears to be an elegant solution, works nicely and seems to fit well with the WO way of doing things, something I am still becoming familiar with.

Anyway, now that I have something working, I was curious how this actually "should" be done, but a search didn't reveal anything "out there" to actually do this using the eomodel to store the relational mapping.

Have I not looked in the right places, or is it just that nobody does it this way?

How does everyone else do this? 


-- 
Seeya...Q

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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