Re: Enum as a model

magic creative <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
<code>
//Enum:

public enum X {
     FIRST, SECOND
}

//Class:

public class Y {

   private X localEnum;

   public X getLocalEnum(){
      return this.localEnum;
   }

   void setLocalEnum(X localEnum){
        this.localEnum = localEnum;
   }

}

//Insance to serve as model:

Y yInstance = new Y();

//Freemaker model:

Map<String, Object> model = new HashMap<String, Object>();
model.put("yInst", yInstance);

//Template:

The value of X in Y: ${yInst.localEnum}

</code>

So what I have is a model which contains an enum and I want simply to show
the assigned value. I have read what you have referenced but I do not see
how to apply it to my quite simple case. On the other hand I read a post
where it is written that the problem with enums is comming from the fact
that instead of getName(), they are reference with name() and thus Freemaker
does not recognize that as property but as function the return value of
which it can not display. I have a hard time however to believe that an enum
can not be used as a model for freemaker, there must be something I have
missed.


On Mon, May 30, 2011 at 7:17 PM, Daniel Dekany <[email protected]> wrote:

> Monday, May 30, 2011, 4:19:06 PM, magic creative wrote:
>
> > Hi guys,
> >
> >  I can not seem to find an example how to solve my problem so let me ask
> directly.
> >
> >  If there is an Enum X which is part of an object Y
>
> What does that mean in Java language?
>
> BTW, just in case you haven't red this, maybe this helps:
> http://freemarker.org/docs/pgui_misc_beanwrapper.html#jdk_15_enums
>
> > I put as model and I reference X in my template I am getting:
> >
> >
> >
> > Expression Y.X is undefined
> >
> >
> > The template has simply ${Y.X}. If X was a String there would be no
> > problem and it would be displayed. As an Enum however it does not
> > work. What should I do to allow enums to be parsed?
> >
> > Kind Regards
> --
> Best regards,
>  Daniel Dekany
>
>

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.