質問

I am currently trying to get an enum as a part of my Tapestry 5 form. So I followed these explanations without success. Indeed I am getting this error :

[...]
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum
    at org.apache.tapestry5.util.EnumValueEncoder.toClient(EnumValueEncoder.java:24) ~[tapestry-core-5.3.3.jar:na]
[...]

So here is what I have in my page class :

@Property
private ScanMode scanMode

(ScanMode is an Enum type) The .tml file :

<t:radiogroup t:value="scanMode">
 <t:label for="recto">Recto</t:label>
 <input t:id="recto" type="radio" t:type="radio" t:value="literal:RECTO"/>
                            <br />
 <t:label for="verso">Recto/Verso</t:label>
 <input t:id="rectoverso" type="radio" t:type="radio" 
                          t:value="literal:RECTO_VERSO"/>
</t:radiogroup>

And finally, my ApplicationModule.java :

private static <T extends Enum> void add(Configuration<CoercionTuple> configuration, Class<T> enumType) {
    configuration.add(CoercionTuple.create(String.class, enumType, StringToEnumCoercion.create(enumType)));
}

public void contributeMasterDispatcher(OrderedConfiguration<Dispatcher> configuration, @InjectService("AccessController") Dispatcher accessController) {
    configuration.add(AccessController.class.getSimpleName(), accessController, "before:PageRender");
}

Any idea would be greatly appreciated !

役に立ちましたか?

解決

http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Radio.html

simplest way (witout converters in AppModule):

@Property
private ScanMode scanMode

public ScanMode getRecto(){ return ScanMode.RECTO; }
public ScanMode getRectoVerso(){ return ScanMode.RECTO_VERSO; }


<t:radiogroup t:value="scanMode" >
    <t:label for="recto">Recto</t:label>
    <t:radio t:id="recto"/>
    <br />
    <t:label for="rectoVerso">Recto/Verso</t:label>
    <t:radio t:id="rectoVerso"/>
</t:radiogroup>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top