Note that there are some explanatory texts on larger screens.

plurals
  1. POTapestry - Enum coercion
    text
    copied!<p>I am currently trying to get an enum as a part of my Tapestry 5 form. So I followed <a href="http://tapestry.apache.org/enum-parameter-recipe.html" rel="nofollow">these explanations</a> without success. Indeed I am getting this error :</p> <pre><code>[...] 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] [...] </code></pre> <p>So here is what I have in my page class :</p> <pre><code>@Property private ScanMode scanMode </code></pre> <p>(ScanMode is an Enum type) The .tml file :</p> <pre><code>&lt;t:radiogroup t:value="scanMode"&gt; &lt;t:label for="recto"&gt;Recto&lt;/t:label&gt; &lt;input t:id="recto" type="radio" t:type="radio" t:value="literal:RECTO"/&gt; &lt;br /&gt; &lt;t:label for="verso"&gt;Recto/Verso&lt;/t:label&gt; &lt;input t:id="rectoverso" type="radio" t:type="radio" t:value="literal:RECTO_VERSO"/&gt; &lt;/t:radiogroup&gt; </code></pre> <p>And finally, my ApplicationModule.java :</p> <pre><code>private static &lt;T extends Enum&gt; void add(Configuration&lt;CoercionTuple&gt; configuration, Class&lt;T&gt; enumType) { configuration.add(CoercionTuple.create(String.class, enumType, StringToEnumCoercion.create(enumType))); } public void contributeMasterDispatcher(OrderedConfiguration&lt;Dispatcher&gt; configuration, @InjectService("AccessController") Dispatcher accessController) { configuration.add(AccessController.class.getSimpleName(), accessController, "before:PageRender"); } </code></pre> <p>Any idea would be greatly appreciated !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload