当以编程方式设置 ValueExpression 时,UISelectItems 值未转换为枚举
UISelectItems value not converted to enum when ValueExpression set programmatically
我正在以编程方式创建 UISelectItems。该值指向一个枚举数组。收到请求后,当 EL 尝试将值转换为枚举时,将抛出 IllegalArgumentException。通过设置断点检查的 UISelectItems 值表达式似乎没有问题。
这是 EnumConfig:
@Named
public class EnumConfig {
public LanguageTag[] getLanguageTagValues() { return LanguageTag.values(); }
}
封装的SelectOneMenu的值表达式如下:
@Model
public class ManageUsersBean {
public LanguageTag getLanguageTag() { return languageTag; }
public void setLanguageTag(LanguageTag arg) { languageTag = arg; }
}
这是堆栈跟踪:
Caused by: java.lang.IllegalArgumentException: No enum constant io.enterprizr.business.model.enumeration.preference.LanguageTag.[Lio.enterprizr.business.model.enumeration.preference.LanguageTag;@5f2ad22c
at java.lang.Enum.valueOf(Enum.java:238) [rt.jar:1.8.0_05]
at com.sun.el.lang.ELSupport.coerceToEnum(ELSupport.java:206) [javax.el-3.0.0.jar:]
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:405) [javax.el-3.0.0.jar:]
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:77) [javax.el-3.0.0.jar:]
at javax.el.ELContext.convertToType(ELContext.java:473) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:229) [javax.el-3.0.0.jar:]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UISelectItems.getValue(UISelectItems.java:129) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:54) [primefaces-5.0.jar:5.0]
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:73) [primefaces-5.0.jar:5.0]
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:67) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:94) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:76) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:47) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1857) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-2.1.0.jar:2.1.0]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:78) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-2.1.0.jar:2.1.0]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1855) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
... 36 more
viewSelectItems
的 expectedType
不对。是 LanguageTag.class
,但应该是 LanguageTag[].class
。
替换(虚构)
createValueExpression("#{enumConfigBean.getLanguageTagValues()}", LanguageTag.class);
来自
createValueExpression("#{enumConfigBean.languageTagValues}", LanguageTag[].class);
我正在以编程方式创建 UISelectItems。该值指向一个枚举数组。收到请求后,当 EL 尝试将值转换为枚举时,将抛出 IllegalArgumentException。通过设置断点检查的 UISelectItems 值表达式似乎没有问题。
这是 EnumConfig:
@Named
public class EnumConfig {
public LanguageTag[] getLanguageTagValues() { return LanguageTag.values(); }
}
封装的SelectOneMenu的值表达式如下:
@Model
public class ManageUsersBean {
public LanguageTag getLanguageTag() { return languageTag; }
public void setLanguageTag(LanguageTag arg) { languageTag = arg; }
}
这是堆栈跟踪:
Caused by: java.lang.IllegalArgumentException: No enum constant io.enterprizr.business.model.enumeration.preference.LanguageTag.[Lio.enterprizr.business.model.enumeration.preference.LanguageTag;@5f2ad22c
at java.lang.Enum.valueOf(Enum.java:238) [rt.jar:1.8.0_05]
at com.sun.el.lang.ELSupport.coerceToEnum(ELSupport.java:206) [javax.el-3.0.0.jar:]
at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:405) [javax.el-3.0.0.jar:]
at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:77) [javax.el-3.0.0.jar:]
at javax.el.ELContext.convertToType(ELContext.java:473) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:229) [javax.el-3.0.0.jar:]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UISelectItems.getValue(UISelectItems.java:129) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:54) [primefaces-5.0.jar:5.0]
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:73) [primefaces-5.0.jar:5.0]
at org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:67) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:94) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:76) [primefaces-5.0.jar:5.0]
at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:47) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:889) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1857) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeRow(PanelGridRenderer.java:142) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeStaticBody(PanelGridRenderer.java:108) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:63) [primefaces-5.0.jar:5.0]
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49) [primefaces-5.0.jar:5.0]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:85) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-2.1.0.jar:2.1.0]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:78) [primefaces-5.0.jar:5.0]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:68) [primefaces-5.0.jar:5.0]
at org.primefaces.extensions.component.layout.LayoutPaneRenderer.encodeBegin(LayoutPaneRenderer.java:152) [primefaces-extensions-2.1.0.jar:2.1.0]
at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1855) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1860) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.6-jbossorg-4.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) [jsf-impl-2.2.6-jbossorg-4.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) [jboss-jsf-api_2.2_spec-2.2.6.jar:2.2.6]
... 36 more
viewSelectItems
的 expectedType
不对。是 LanguageTag.class
,但应该是 LanguageTag[].class
。
替换(虚构)
createValueExpression("#{enumConfigBean.getLanguageTagValues()}", LanguageTag.class);
来自
createValueExpression("#{enumConfigBean.languageTagValues}", LanguageTag[].class);