我的目的是从datatable中获取后端bean的值,我将通过单击选择特定的行,使用属性“rowSelectListener”我将点击后端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
如何纠正此错误。
答案 0 :(得分:1)
学习阅读例外并调试代码。你得到的错误是由:
引起的引起:java.lang.ClassCastException:com.eschool.model.StudentAttendanceTable无法强制转换为[Ljava.lang.Integer; 在com.eschool.bean.AdminStudentAttendenceMBean.rowListener(AdminStudentAttendenceMBean.java:539)
异常非常明确:您正试图从StudentAttendanceTable
投射到Integer[]
,这显然是不对的。因此,请转到代码的AdminStudentAttendenceMBean.java:539
行,并向编译器解释您实际上想要做的事情。