JSF 2.0中的UpdateModelException ClassCastException

时间:2011-10-23 15:34:17

标签: jsf jsf-2 facelets el classcastexception

我有一个带有ui:repeat标签的facelets页面,它输出HTML表的行,每行接受用户输入。这可以罚款。我还有第二组数据,我使用相同的页面和转发器输出(只是不同的数据)。支持此页面的支持bean是ConversationScoped。

<ui:repeat value="#{cloneBuilderBean.pageTemplate}" var="row" varStatus="status">
  <tr>
    <td>#{row.label}</td>
    <td><h:inputText value=#{row.value}/></td>
  </tr>
</ui:repeat>

我遇到的问题是当用户点击h:commandButton以“继续”到下一页时。这实际上只是重新显示当前页面,但转发器的集合已更新为一组新数据。从我的调试开始,看起来我甚至没有看到因为单击commandButton转到下一页而应该触发的action方法。下面的堆栈跟踪也没有显示任何命中我的代码的迹象。有关如何解决此错误的任何想法?

javax.faces.component.UpdateModelException: java.lang.ClassCastException
    at javax.faces.component.UIInput.updateModel(UIInput.java:853)
    at javax.faces.component.UIInput.processUpdates(UIInput.java:735)
    at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:525)
    at com.sun.faces.facelets.component.UIRepeat.processUpdates(UIRepeat.java:748)
    at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
    at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
    at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassCastException
    at javax.el.ArrayELResolver.setValue(ArrayELResolver.java:257)
    at com.sun.faces.el.DemuxCompositeELResolver._setValue(DemuxCompositeELResolver.java:255)
    at com.sun.faces.el.DemuxCompositeELResolver.setValue(DemuxCompositeELResolver.java:281)
    at com.sun.el.parser.AstValue.setValue(AstValue.java:197)
    at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:286)
    at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:74)
    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
    at javax.faces.component.UIInput.updateModel(UIInput.java:818)
    ... 41 more

更新:相关的bean代码如下:

private int[] part1,part2;
private int[] currentPart; //pointer to part1 or part2
private List<SelectItem> pageTemplate;

public String openItem(String value){
    conversation.begin();

    //database dummy data...
    pageTemplate = new ArrayList(4);
    pageTemplate.add(new SelectItem("Data1"));
    pageTemplate.add(new SelectItem("Data2"));
    pageTemplate.add(new SelectItem("Data3"));
    pageTemplate.add(new SelectItem("Data4"));

    //database dummy data...
    part1 = new int[4];
    for(int i = 0; i < part1.length; i++){
        part1[i] = i+1;
    }
    currentPart = part1;

    return "page2";
}

public String next(){
    //database dummy data...
    part2 = new int[4];
    for(int i = 0; i < part2.length; i++){
        part2[i] = i+2;
    }
    currentPart = part2;
    return "page2";
}

相关的观看代码是:

<ui:repeat value="#{CloneBuilderBean.pageTemplate}" var="row" varStatus="status">
    <tr>
        <td>#{row.value}</td>
        <td width="300">
            <h:inputHidden id="val" value="#{CloneBuilderBean.currentPart[status.index]}" />
            <p:slider for="val" step="1" style="width:90%;" minValue="0" maxValue="7" />
        </td>
    </tr>
</ui:repeat>

<h:commandButton value="display part 2" action="#{CloneBuilderBean.next()}"/>

1 个答案:

答案 0 :(得分:2)

  

引起:java.lang.ClassCastException
    在javax.el.ArrayELResolver.setValue(ArrayELResolver.java:257)

我转载了你的问题。事实证明,#{CloneBuilderBean.currentPart[status.index]}设置为Integer而不是int。当我将int[]替换为Integer[]时,它适用于我。

当我尝试在Tomcat 7.0.19而不是Glassfish 3.1.1上重现您的问题时,我从其EL解析器中得到了一个更明确的异常:

  

引起:java.lang.ClassCastException:无法将[java.lang.Integer]类型的对象添加到[int]类型的对象数组中     在javax.el.ArrayELResolver.setValue(ArrayELResolver.java:96)