Yes... that's true ;). I think i will try to use Covnerters, as Gert
Vanthienen suggested to me... I've already read some articles about
converters and it sounds like a convenient method... And I don't have to mix
presentation layer with business layer, which of course isn't possible
always anyway...

But thx for your answer, you helped me anyway (didn't knew it's possible to
access messages from the bundle in the way you've described.

Thx,
Dominik

-----Ursprüngliche Nachricht-----
Von: Andrew Robinson [mailto:[EMAIL PROTECTED] 
Gesendet: Donnerstag, 26. Oktober 2006 17:22
An: MyFaces Discussion
Betreff: Re: AW: Best Practice - Converting raw property values of Beans

It is "cheating" because I put UI specific code in my enumeration (the
bundle key). I didn't feel that great about it, but it worked well
enough for me to use it.

On 10/25/06, Jonathan Harley <[EMAIL PROTECTED]> wrote:
> Bieringer Dominik wrote:
> > Hey cool... thx very much... I didn't knew about the possibility to
access
> > the message from the bundle via
> >
> > <t:outputText value="#{msg[exampleBean.testEnum.bundleKey]}" />
> >
> > That makes life easier.
>
> It does, but you still have to declare the message bundle for "msg".
> There's a technique I like that simplifies things even further, which
> is to use an EL function to do the bundle lookup - then you don't even
> have to declare the resource bundle, just the function namespace, which
> is the same on every page. That makes it easy to reorganise and rename
> message bundles without having to change every page.
>
> > -----Ursprüngliche Nachricht-----
> > Von: Andrew Robinson [mailto:[EMAIL PROTECTED]
> > Gesendet: Mittwoch, 25. Oktober 2006 22:30
> > An: MyFaces Discussion
> > Betreff: Re: Best Practice - Converting raw property values of Beans
> >
> > I "cheated" and made an interface for enum types:
>
> (Why is this cheating?)
>
> > public interfaces EnumDescribed
> > {
> >   public String getBundleKey();
> > }
> >
> > public enum TestEnum
> >   implements EnumDescribed
> > {
> >   A("test.a"),
> >   B("test.b");
> >   private final String bundleKey;
> >   private TestEnum(String bundleKey)
> >   {
> >     this.bundleKey = bundleKey;
> >   }
> >   public String getBundleKey()
> >   {
> >     return this.bundleKey;
> >   }
> > }
> >
> > public class ExampleBean
> > {
> >   private TestEnum testEnum;
> >   public TestEnum getTestEnum() { return this.testEnum; }
> > }
> >
> > <t:outputText value="#{msg[exampleBean.testEnum.bundleKey]}" />
> >
> > -Andrew
>
> I've been using a similar technique, but it seems to me that there's
> no reason to invent those "test.a" strings and store them in your Enum.
> Why should the Enum have to know about the structure of resource
> bundles, which may be authored by different folks to the Java
> developers? So I use the Enum's name (A and B in the example above)
> with a method like this:
>
> public String getBundleKey() {
>    return name();
> }
>
> Or you could use the class name + enum name if you're worried about
> name clashes. Then the Enum doesn't need to know anything about the
> view layer.
>
>
> Jonathan
> --
> .....................................................................
>            Dr Jonathan Harley   .
>                                 .   Email: [EMAIL PROTECTED]
>             Zac Parkplatz Ltd   .   Office Telephone: 024 7633 1375
>             www.parkplatz.net   .   Mobile: 079 4116 0423
>

Reply via email to