1 Reply Latest reply on Feb 14, 2012 9:19 AM by Jorge Campos

    Dynamic rich:datatable with el expression

    Jorge Campos Newbie

      Hello guys,

       

      I'm creating a dynamic datatable (richfaces 3.3.3.Final) with a datascroller (in order to paginate the grid). But I couldn't get it work properly with EL Expression

       

      I have a panel, inside then I have a dataScroller and a data table and all of this is inside another panel.

       

      The main question is why does this not work?

       

      Add a value expression as a value in a data table

      table.setValueExpression("value", GeradorUtil.createValueExpression("#{geradorRelatorioManagerBean.listaPaginada}"));

       

       

      CODES:

       

      //PANEL
      HtmlPanelGrid painel = new HtmlPanelGrid();
      painel.setId( "datagridPanel" );
      
      
      //TABLE
      HtmlDataTable table = new HtmlDataTable();
      table.setId("dataTableSomeId");
      table.setVar("_lista");
      table.setRows(10);
      // >>>>>>>>>>>>>>>>>>>>> THIS IS NOT WORKING (the getListaPaginada() method code is below)<<<<<<<<<<<<<<<<<<<<<
      table.setValueExpression("value", GeradorUtil.createValueExpression("#{geradorRelatorioManagerBean.listaPaginada}"));
      
      
      table.getChildren().add( buildColuna("codigo", "Código", table.getVar()) );
      table.getChildren().add( buildColuna("descricao", "Descrição", table.getVar()) );
      
      
      //METHOD buildColuna
      private UIComponent buildColuna(String varValue, String title, String var){
                HtmlOutputText header = new HtmlOutputText();
                header.setId( "id" + varValue + "Header" );
                header.setValueExpression("value", GeradorUtil.createValueExpression( title ));
      
                HtmlColumn coluna = new HtmlColumn();
                coluna.setId( "Idcol" + varValue );
                coluna.setHeader(header);
                coluna.setStyleClass("font-normal");
      
                HtmlOutputText txtColuna = new HtmlOutputText();
                txtColuna.setId(par.getNome() + "tx" + varValue );
                txtColuna.setValueExpression("value", GeradorUtil.createValueExpression("#{" + var + "." + varValue + "}") );
                coluna.getChildren().add(txtColuna);
      
                return coluna;
      }
      
      
      
      
      //SCROLLER
      HtmlDatascroller scroll = new HtmlDatascroller();
      scroll.setId("scroll");
      scroll.setFor("dataTableSomeId");
      scroll.setMaxPages(5);
      scroll.setStepControls("hide");
      scroll.setAlign("right");
      scroll.setReRender( "datagridPanel" );
      scroll.setRequestDelay(500);
      scroll.setIgnoreDupResponses(true);
      scroll.setEventsQueue( "scrollQueue");
      
      
      //ADDing SCROLL and TABLE TO the Panel
      painel.getChildren().add( scroll );
      painel.getChildren().add( table );
      
      
      //ObjetoComponenteDinamico
      public class ObjetoComponenteDinamico {
      String codigo
      String descricao
      //gets and sets and hash and equals methods
      }
      
      
      //METHOD getListaPaginada()
      /**
       * Metodo responsavel por implementar um {@link org.richfaces.model.DataProvider} que realizara a paginação sob demanda. 
       * @return ExtendedTableDataModel
       */ 
      public ExtendedTableDataModel<ObjetoComponenteDinamico> getListaPaginada() {
      
      
                lista =  new ExtendedTableDataModel<ObjetoComponenteDinamico>(new DataProvider<ObjetoComponenteDinamico>() {
      
      
                          private static final long serialVersionUID = 1L;
      
      
                          @Override
                          public ObjetoComponenteDinamico getItemByKey(Object _CurrentHashCode) {
                                    for (ObjetoComponenteDinamico obj : listaAuxiliar) {
                                              if (obj.hashCode() == (Integer)_CurrentHashCode)
                                                        return obj;
                                    }
                                    return null;
                          }
      
      
                          @Override
                          public List<ObjetoComponenteDinamico> getItemsByRange(int firstRow, int endRow) {
                                    PaginatedList<ObjetoComponenteDinamico> paginatedList = new PaginatedList<ObjetoComponenteDinamico>();
                                    try {
      
                                                        paginatedList = new PaginatedList<ObjetoComponenteDinamico>(firstRow, endRow); 
                                                        paginatedList.setSkipResults(firstRow);
                                                        paginatedList.setMaxResults(endRow);
      
                                                        listaAuxiliar = geradorEngine.listaPaginadaDinamica(consulta, paginatedList);
      
                                              return listaAuxiliar;
      
                                    } catch (GeradorEngineException e) {
                                              jsfUtil.addMessageError("Nenhum registro encontrado."); 
                                    } catch (Exception e) {
                                              jsfUtil.addMessageError(e.getMessage());
                                    }
                                    return null;
                          }
      
      
                          @Override
                          public Object getKey(ObjetoComponenteDinamico objetoComponenteDinamico) {
                                    return objetoComponenteDinamico.hashCode();
                          }
      
      
                          @Override
                          public int getRowCount() {
                                    try {
                                              return geradorEngine.listaPaginadaDinamica(consulta, null).getTotalCount();
                                    } catch (GeradorEngineException e) {
                                              jsfUtil.addMessageError(e.getMessage());
                                    } catch (Exception e) {
                                              jsfUtil.addMessageError(e.getMessage());
                                    }
                                    return 0;
                          }
                });
      
                return lista;
      }
      
      

       

      The XHTML code is:

       

      <!-- I have a method in my bean to bind this panel wich add the datatable above -->
      <h:panelGrid id="renderPanel" binding="#{geradorRelatorioManagerBean.renderPanel}"/>
      

       

      In order to test my methods I have the exactly same code in XHTML and is working fine

       

       

        <h:panelGrid id="togglePanelLista"> 
                <div align="right">
      
                <rich:datascroller for="processosList" maxPages="5"
                          stepControls="hide"
                          reRender="togglePanelLista" align="right" requestDelay="500"
                          ignoreDupResponses="true" eventsQueue="fila" />
      
                </div>
                <rich:dataTable id="processosList" 
                                              value="#{geradorRelatorioManagerBean.listaPaginada}"
                                              var="_processo" 
                                              rows="10"
                                              onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                                              onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'">
      
                          <rich:column>
                                    <f:facet name="header">codigo</f:facet> 
                                    <h:outputText value="#{_processo.codigo}" styleClass="font-normal"/>
                          </rich:column>
      
                          <rich:column rendered="#{geradorRelatorioProcessamentoBean.podePararProcesso}">
                                    <f:facet name="header">descricao</f:facet> 
                                    <h:outputText value="#{_processo.descricao}" styleClass="font-normal"/>
                          </rich:column>            
                </rich:dataTable>
      </h:panelGrid>
      
      

       

       

      When I run the dynamic code I get this error:

       

       

      javax.el.PropertyNotFoundException: Property 'codigo' is not found on type: java.lang.String
      
      javax.faces.FacesException: javax.el.PropertyNotFoundException: Property 'codigo' is not found on type: java.lang.String
       at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
       at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:201)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:284)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:281)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:279)
       at org.richfaces.renderkit.AbstractRowsRenderer.encodeCellChildren(AbstractRowsRenderer.java:288)
       at org.richfaces.renderkit.AbstractTableRenderer.encodeOneRow(AbstractTableRenderer.java:391)
       at org.richfaces.renderkit.AbstractRowsRenderer.process(AbstractRowsRenderer.java:83)
       at org.ajax4jsf.model.SequenceDataModel.walk(SequenceDataModel.java:101)
       at org.ajax4jsf.component.UIDataAdaptorBase.walk(UIDataAdaptorBase.java:1156)
       at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:104)
       at org.richfaces.renderkit.AbstractRowsRenderer.encodeRows(AbstractRowsRenderer.java:88)
       at org.richfaces.renderkit.AbstractTableRenderer.encodeTBody(AbstractTableRenderer.java:90)
       at org.richfaces.renderkit.AbstractTableRenderer.encodeChildren(AbstractTableRenderer.java:97)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.ajax4jsf.renderkit.html.AjaxOutputPanelRenderer.encodeChildren(AjaxOutputPanelRenderer.java:78)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
       at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
       at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
       at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:180)
       at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:127)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:279)
       at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
       at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:301)
       at org.richfaces.renderkit.html.SimpleToggleControlTemplate.doEncodeChildren(SimpleToggleControlTemplate.java:296)
       at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
       at org.richfaces.renderkit.html.SimpleTogglePanelRenderer.encodeChildren(SimpleTogglePanelRenderer.java:188)
       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:594)
       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.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at br.com.unimedfortaleza.sabius.common.security.SecurityFilter.doFilter(SecurityFilter.java:217)
       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:190)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
       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.authenticator.SingleSignOn.invoke(SingleSignOn.java:383)
       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:447)
       at java.lang.Thread.run(Thread.java:619)
      Caused by: javax.el.PropertyNotFoundException: Property 'codigo' is not found on type: java.lang.String
       at javax.el.BeanELResolver.getValue(BeanELResolver.java:230)
       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:135)
       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
       at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
       at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
       at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
       at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
       ... 78 more
      
      
      

       

       

      I alrealdy use in my table.setValue( myBean.getListaPaginada() ) wich shows the grid with the first 10 rows but the scroller don't work

       

      Any help will be appreciated

       

      Thanks

      Jorge Campos

        • 1. Re: Dynamic rich:datatable with el expression
          Jorge Campos Newbie

          As usual no one has answered my question...

          So, I did my researchs and try attempts and finnaly get it to work...

           

          But it only work with a deprecated method, so is this right??

           

          anyway here is the fix of my problem.

           

          Instead of use:

          table.setValueExpression("value", GeradorUtil.createValueExpression("#{geradorRelatorioManagerBean.listaPaginada}"));

           

          I used

           

          table.setValueBinding("value", GeradorUtil.createValueBinding("#{genericPaginatedListBean.listaPaginada}"));

           

          this method setValueBinding is deprecated I'm wondering why work just with it!

           

          the methods that I'm using for create the expressions is:

           

          @SuppressWarnings("deprecation")

          public static ValueBinding createValueBinding( String value ){

                              return FacesContext.getCurrentInstance()

                                                            .getApplication().createValueBinding( value );

                    }

           

          public static ValueExpression createValueExpression( String value ){

                              FacesContext context = FacesContext.getCurrentInstance();

                              return context.getApplication().getExpressionFactory(). 

                                                createValueExpression( context.getELContext(), value, String.class);

                    }

           

          I'm getting good at creation of dynamic stuff with richfaces

          1 of 1 people found this helpful