首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tapestry - Enum强制

Tapestry - Enum强制
EN

Stack Overflow用户
提问于 2013-01-31 22:47:21
回答 1查看 1.6K关注 0票数 1

我目前正在尝试将枚举作为我的Tapestry 5表单的一部分。所以我跟踪了these explanations,但没有成功。事实上,我得到了这个错误:

代码语言:javascript
复制
[...]
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]
[...]

下面是我的页面类中的内容:

代码语言:javascript
复制
@Property
private ScanMode scanMode

(ScanMode是枚举类型) .tml文件:

代码语言:javascript
复制
<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>

最后,我的ApplicationModule.java:

代码语言:javascript
复制
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");
}

任何想法都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-31 23:55:31

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

最简单的方法(AppModule中的witout转换器):

代码语言:javascript
复制
@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>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14628502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档