How would I create this special enum converter?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How would I create this special enum converter?

Dave Alvarado
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: How would I create this special enum converter?

david@butterdev.com
It would be very simple to write your own converter to get the behavior you want.  Download the source and take a look at the EnumConverter, then modify as needed.  Then simply add an init section to your dwr.xml where you define the new converter (and of course add a convert element for SpecialEnum using the new converter).

On 04/02/2014 02:58 PM, Dave Alvarado wrote:
Hi,

I’m using DWR 3.0.0-rc2.  I want to define a converter for an enum I have created, but it doesn’t quite conform to the way the documentation talks about enum conversions.  My enum is …

public enum SpecialEnum
{

   SUBJECT1(“first subject), 
   SUBJECT2(“second subject”);

   SpecialEnum(final String name)
   {
       this.name = name;
   }

   private final String name;
   @Override
   public String toString()
   {
       return getName();
   }

   public String getName()
   {
       return this.name;
   }
}

My wish is that on the Javascript side if a field is defined as “second subject”, it will be interpreted as SpecialEnum.SUBJECT2 on the server side and vice-versa.  What is the simplest way to do this?

Thanks, - Dave