A quick example of declaring an enum type and using it as a parameter in a Tapestry component.

Declaring the enum type

     public enum Day {
          SUNDAY, MONDAY, TUESDAY, WEDNESDAY, 
          THURSDAY, FRIDAY, SATURDAY 
     }

Declaring the enum parameter in a component class

    @Parameter
    private Day day;

Adding the String To Enum type coercion

In order to use literal string values for your enum parameter in your component, add a coercion from String to your enum class by adding the following code to your module class

     public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration) {
         configuration.add(new CoercionTuple<String, Day>(
             String.class,
             Day.class,
             StringToEnumCoercion.create(Day.class)
         ));
     }

Passing a literal string value to your enum parameter

    <t:mycomponent day="literal:WEDNESDAY" />

Tapestry5EnumAsComponentParameter (last edited 2009-11-19 00:46:13 by LeonardLu)