8 Replies Latest reply on Feb 18, 2009 1:18 PM by Serhiy Zastavnyy

    dynamic ExtendedDataTable filtering

    Serhiy Zastavnyy Novice

      Hi

      Help me please. I am new to richfaces.
      I created dynamically ExtendedDataTable, but I do not see filter field. When I did it using web component everything was fine and I had possibility to filter my data. Dynamically I filled the same properties.
      Is there some trick to display filter field creating ExtendedDataTable dynamically?
      I see a lot of examples using web components. Is there knowledge base how to work with richfaces dynamically ? Some books, articles or someting else?

      Thank you in advance.

        • 1. Re: dynamic ExtendedDataTable filtering
          Nick Belaevski Master

          Hello,

          There's nothing special in creating components dynamically, probably you haven't filled some necessary attribute. Please post your bean code.

          • 2. Re: dynamic ExtendedDataTable filtering
            Serhiy Zastavnyy Novice

            Here is my code. I use 3.3.0 version. Please point.

             ExpressionFactory elFactory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
             ELContext elContext = FacesContext.getCurrentInstance().getELContext();
            
             HtmlExtendedDataTable list = new HtmlExtendedDataTable();
             list.setId("clUserList");
             list.setValueExpression("value",
             elFactory.createValueExpression(elContext, "#{extendedDataTableBean.dataModel}", ExtendedTableDataModel.class));
             list.setWidth("100%");
             list.setHeight("200px");
             list.setSelectedClass("dataTableSelectedRow");
             list.setSortMode("single");
             list.setSelectionMode("single");
             list.setValueExpression("selection",
             elFactory.createValueExpression(elContext, "#{extendedDataTableBean.selection}", SimpleSelection.class));
             list.setRowKeyVar("rkvar");
             list.setValueExpression("tableState",
             elFactory.createValueExpression(elContext, "#{extendedDataTableBean.tableState}", String.class));
             list.setVar("item");
            
             HtmlColumn idCol = new HtmlColumn();
             idCol.setId("clUserListId");
             ValueExpression idExpr = elFactory.createValueExpression(elContext, "#{item.id}", String.class);
             idCol.setHeaderClass("dataTableHeader");
             idCol.setWidth("150px");
             idCol.setLabel("ID");
             HtmlOutputText idContent = new HtmlOutputText();
             idContent.setValueExpression("value", idExpr);
             idCol.getChildren().add(idContent);
             HtmlOutputText idHeader = new HtmlOutputText();
             idHeader.setValue("ID");
             idCol.getFacets().put("header", idHeader);
             list.getChildren().add(idCol);
            
             HtmlColumn nameCol = new HtmlColumn();
             nameCol.setId("clUserListName");
             ValueExpression nameExpr = elFactory.createValueExpression(elContext, "#{item.name}", String.class);
             nameCol.setHeaderClass("dataTableHeader");
             nameCol.setWidth("150px");
             nameCol.setLabel("Name");
             nameCol.setSelfSorted(false);
             nameCol.setSortBy(nameExpr);
             nameCol.setFilterBy(nameExpr);
             nameCol.setFilterEvent("onkeyup");
             HtmlOutputText nameContent = new HtmlOutputText();
             nameContent.setValueExpression("value", nameExpr);
             nameCol.getChildren().add(nameContent);
             HtmlOutputText nameHeader = new HtmlOutputText();
             nameHeader.setValue("Name");
             nameCol.getFacets().put("header", nameHeader);
             list.getChildren().add(nameCol);
            


            • 3. Re: dynamic ExtendedDataTable filtering
              Serhiy Zastavnyy Novice

              I tried to use

              nameCol.setSelfSorted(true);
              

              and
              nameCol.setSortable(true);
              

              also

              • 4. Re: dynamic ExtendedDataTable filtering
                Nick Belaevski Master

                Try this:

                nameCol.setValueExpression("filterBy", nameExpr)


                • 5. Re: dynamic ExtendedDataTable filtering
                  Serhiy Zastavnyy Novice

                  It works now.
                  Thank you.

                  • 6. Re: dynamic ExtendedDataTable filtering
                    Serhiy Zastavnyy Novice

                    One more question. Help me please.

                    I tried to use 1 bean for 2 extendedDataTables (I have selector between different data in extendedDataTable model).
                    But I can not.
                    I pressed button A and first table displayed successfully.
                    I pressed button B and displayed second table but there was data of first table. It looks like some cash is used.
                    In logs I found that when second table displayed, application did not call my extendedDataTable model methods.
                    All my code is above. ExtendedDataTable Model I created as in richfaces samples.

                    Should I redefine some methods in ExtendedDataTable bean and use there my selector between different data
                    or is there way not to use cash (data always load from model)
                    or are there another ways to use 1 bean for 2 tables?

                    Please help.

                    • 7. Re: dynamic ExtendedDataTable filtering
                      Nick Belaevski Master

                      Please post page code.

                      • 8. Re: dynamic ExtendedDataTable filtering
                        Serhiy Zastavnyy Novice

                        Problem is solved.
                        I have used reset() method for exTableData model.