0

我的意图是从数据表中获取 back bean 的值,我将通过单击选择特定行,使用属性“rowSelectListener”我将点击 back bean 中可用的方法。问题是,我在单个项目中得到它,当我尝试与我的项目集成时,它显示方法调用错误。

这是我的xhtml编码。

<ace:dataTable id="studAttendanceTable"
                selectionMode="single"
                value="#{adminStudentAttendenceMBean.allStudentAttendanceList}"
                var="someVar" paginator="true" rows="12"
                rowSelectListener="#{adminStudentAttendenceMBean.rowListener}">

<ace:column headerText="Month">
         <h:outputText value="#{someVar.month}" />
</ace:column>

<ace:column headerText="Year">
         <h:outputText value="#{someVar.year}"/>
</ace:column>

<ace:column headerText="Id">
         <h:outputText value="#{someVar.studentInfoTable.studentId}" />
</ace:column>

<ace:column headerText="Student Name">
         <h:outputText value="#{someVar.studentInfoTable.studentName}" />
</ace:column>

</ace:dataTable>

我的豆类:

public void rowListener(SelectEvent e) {
            Integer[] selectedRow = (Integer[]) e.getObject();
            List<StudentAttendanceTable> editList = new ArrayList<StudentAttendanceTable>(Arrays.asList((StudentAttendanceTable)e.getObject()));
            for(StudentAttendanceTable ele :editList)
            System.out.println(ele.getStudentAttendanceId());
        }

这里的错误代码是:

Dec 13, 2013 4:01:32 PM com.sun.faces.lifecycle.InvokeApplicationPhase execute
WARNING: /admin/studentattendance.xhtml @50,76 rowSelectListener="#{adminStudentAttendenceMBean.rowListener}": java.lang.ClassCastException: com.eschool.model.StudentAttendanceTable cannot be cast to [Ljava.lang.Integer;
javax.el.ELException: /admin/studentattendance.xhtml @50,76 rowSelectListener="#{adminStudentAttendenceMBean.rowListener}": java.lang.ClassCastException: com.eschool.model.StudentAttendanceTable cannot be cast to [Ljava.lang.Integer;
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
    at org.icefaces.ace.component.datatable.DataTable.broadcast(DataTable.java:318)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:786)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1251)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    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.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.eschool.util.SessionValidationFilter.doFilter(SessionValidationFilter.java:55)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: com.eschool.model.StudentAttendanceTable cannot be cast to [Ljava.lang.Integer;
    at com.eschool.bean.AdminStudentAttendenceMBean.rowListener(AdminStudentAttendenceMBean.java:539)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    ... 26 more

如何纠正这个错误。

4

1 回答 1

1

学习阅读异常并调试您的代码。您遇到的错误是由以下原因引起的:

引起:java.lang.ClassCastException:com.eschool.model.StudentAttendanceTable 无法转换为 [Ljava.lang.Integer; 在 com.eschool.bean.AdminStudentAttendenceMBean.rowListener(AdminStudentAttendenceMBean.java:539)

例外很明显:你试图从StudentAttendanceTable显然Integer[]不正确的地方转换。因此,转到AdminStudentAttendenceMBean.java:539您的代码行并向编译器解释您实际上想要做什么。

于 2013-12-13T11:02:50.317 回答