3 Replies Latest reply on Jan 11, 2012 3:42 AM by kamal perera

    how to use entiy query data model

    kamal perera Newbie

      Hi,


      Is there any example on how to use the datamodel in entity query. It is giving me java.lang.ClassCastException: java.util.ArrayList cannot be cast to javax.faces.model.DataModel when I bind it to my data table .The entityquery class in in converstion scope.


      Thank You

        • 1. Re: how to use entiy query data model
          Emir Calabuch Newbie

          It is very easy. Create the list and annotate it with @DataModel, then create a factory method that populates the list (the factory method should be of void return type). Like this:


          @Name("dataModelTest")
          public class DataModelTest {
            @DataModel List<String> messageList = new ArrayList<String>();
            @DataModelSelection String selectedString;
          
            @Factory("messageList")
            public void loadMessages() {
              // Your code retrieves the data for the list
              messageList.add("One string");
              messageList.add("Another string");
              messageList.add("Third");
            }
          
            publc void myAction() {
              // Here you will see that "selectedString" variable 
              // contains the value of the selected element in the datamodel
              System.out.println(selectedMessage);
            }
          }
          



          And on your page:


          <h:form>
            <rich:dataTable var="m" value="#{messageList}">
              <rich:column>
                <h:commandLink action="#{dataModelTest.myAction()}">#{m}</h:commandLink>
              </rich:column>
            </rich:dataTable>
          </h:form>
          



          The table lists the strings in the datamodel and a link for each. When you click on the link, the action receives the selected item in the datamodel selection. Of course you can use your own class instead of plain String datamodels.

          • 2. Re: how to use entiy query data model
            kamal perera Newbie

            Thanks Emir,
            but I am specifying about the datamodel that is embedded with the EntityQuery. I tried to use it ith my data table but the above exception is coming when I rerendered the table after a search. The binding is as follows,




            <rich:dataTable id="myList"
                               var="_myList"
                             value="#{myList.dataModel}"
                        rowClasses="row2, row1"
                         transient="true"
                          rendered="#{not empty myList.resultList}">





            but if I use

            #{myList.resultList}

            as the value the table renders properly and shows my search  results(But as I need to get the selected row for some operations I need to use the datamodel).


            Any suggestions on this?

            • 3. Re: how to use entiy query data model
              kamal perera Newbie

              Actually this issue is coming in the Sort template I have added. The complete stack trace is as follows,




              01:39:21,638 SEVERE [viewhandler] Error Rendering View[/cpm/gldcrs/LxTwSummaryRateList.xhtml]
              java.lang.ClassCastException: java.util.ArrayList cannot be cast to javax.faces.model.DataModel
                   at org.jboss.seam.ui.component.UISelection.getValue(UISelection.java:54)
                   at org.jboss.seam.ui.util.ViewUrlBuilder.addParameter(ViewUrlBuilder.java:43)
                   at org.jboss.seam.ui.component.UISeamCommandBase.getUrl(UISeamCommandBase.java:117)
                   at org.jboss.seam.ui.renderkit.LinkRendererBase.doEncodeBegin(LinkRendererBase.java:26)
                   at org.jboss.seam.ui.util.cdk.RendererBase.encodeBegin(RendererBase.java:79)
                   at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:275)
                   at org.richfaces.renderkit.AbstractTableRenderer.encodeHeaderFacets(AbstractTableRenderer.java:299)
                   at org.richfaces.renderkit.AbstractTableRenderer.encodeHeader(AbstractTableRenderer.java:192)
                   at org.richfaces.renderkit.AbstractTableRenderer.encodeTableStructure(AbstractTableRenderer.java:159)
                   at org.richfaces.renderkit.html.DataTableRenderer.doEncodeBegin(DataTableRenderer.java:160)
                   at org.richfaces.renderkit.html.DataTableRenderer.doEncodeBegin(DataTableRenderer.java:148)
                   at org.ajax4jsf.renderkit.RendererBase.encodeBegin(RendererBase.java:100)
                   at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
                   at javax.faces.component.UIData.encodeBegin(UIData.java:967)
                   at org.ajax4jsf.component.UIDataAdaptor.encodeBegin(UIDataAdaptor.java:1202)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:275)
                   at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
                   at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:348)
                   at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:343)
                   at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
                   at org.richfaces.renderkit.html.SimpleTogglePanelRenderer.encodeChildren(SimpleTogglePanelRenderer.java:186)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                   at javax.faces.render.Renderer.encodeChildren(Renderer.java:148)
                   at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                   at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:166)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:83)
                   at org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:157)
                   at org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
                   at org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
                   at org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
                   at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                   at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                   at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                   at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                   at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                   at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                   at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                   at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:295)
                   at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:373)
                   at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:500)
                   at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
                   at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                   at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                   at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:183)
                   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                   at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:95)
                   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                   at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                   at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:451)
                   at java.lang.Thread.run(Thread.java:662)