【发布时间】:2011-12-09 14:31:34
【问题描述】:
我正在尝试根据 dataType 值动态呈现 Richfaces 和 jsf UI 元素。
例如:我有一个如下的枚举
public enum DataType {
DT_LONGLONG(1), DT_STRING(2), DT_LONG(3), DT_DATE(4), DS_EXTERNALREFERENCE(5),
DT_BOOLEAN(6), DT_FLOAT(7), DT_SHORT(8);
}
然后在 xhtml 页面中遍历我的自定义对象列表时,我检查 dataType 并相应地呈现 UI 元素,如下所示:
<c:if test="#{meaCompPartAttr.dataType.dataType == 2}">
<h:inputText />
</c:if>
<c:if test="#{(meaCompPartAttr.dataType.dataType == 1) or
(meaCompPartAttr.dataType.dataType == 3) or
(meaCompPartAttr.dataType.dataType == 8)}">
<h:inputText onkeyup="javascript:validateField(this, '#{tpMsgs.longRegularExpression}');">
<f:validateLongRange/>
</h:inputText>
</c:if>
<c:if test="#{meaCompPartAttr.dataType.dataType == 7}">
<h:inputText onkeyup="javascript:validateField(this, '#{tpMsgs.doubleRegularExpression}');">
<f:validateDoubleRange/>
</h:inputText>
</c:if>
<c:if test="#{meaCompPartAttr.dataType.dataType == 6}">
<h:selectBooleanCheckbox />
</c:if>
<c:if test="#{meaCompPartAttr.dataType.dataType == 4}">
<rich:calendar />
</c:if>
因此,我通常会遇到类转换异常,例如 String to Boolean 或 Long to String 等。我认为这是因为 jstl 和 jsf 代码不同步运行。
是否有任何其他方法可以按照上述示例中的建议动态呈现 UI 元素?
【问题讨论】:
标签: jsf enums richfaces jstl facelets