سؤال

My intention is to get value in back bean from datatable, i will select particular row by click, using attribute "rowSelectListener" i will hit the method which is available in back bean. The thing is, i got it in individual project, when i try to integrate with my project it showing an error with method calling.

This is my xhtml coding.

<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>

My Bean Class:

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());
        }

Here the error code is:

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

How to rectify this error.

هل كانت مفيدة؟

المحلول

Learn to read the exceptions and debug your code. The error you've got is caused by:

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)

The exception is quite clear: you are trying to cast from StudentAttendanceTable to Integer[] which is obviously not right. So go to AdminStudentAttendenceMBean.java:539 line of your code and explain to the compiler what you in fact want to do.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top