13 Replies Latest reply on Mar 4, 2008 4:07 AM by smilidon

    refresh/rerender whole datatable

    smilidon

      Hi,

      i need to update a whole table, because i add columns dynamic. The datatable is bound to a backing bean:


      <rich:datatable id="detailsTable" binding="#{newEvent.detailsHtmlTable}">
       </rich:datatable>
      


      the getter of my bean:

      
      public HtmlDataTable getDetailsHtmlTable(){
      
       detailsHtmlTable = new HtmlDataTable();
       detailsHtmlTable.setId("detailsTable");
       detailsHtmlTable.setValueExpression("value",
       createValueExpression("#{newEvent.dateList}", ArrayList.class));
       detailsHtmlTable.setVar("record");
      
       HtmlColumn column = new HtmlColumn();
      
       HtmlOutputText dateText = new HtmlOutputText();
       dateText.setValueExpression("value",
       createValueExpression("#{record.eventDate}", Date.class));
       column.getChildren().add(dateText);
       detailsHtmlTable.getChildren().add(column);
      
       HtmlOutputText detailText;
       HtmlColumn detailColumn;
       for (int i = 0; i < DETAIL_SIZE; i++){
       detailText = new HtmlOutputText();
       detailText.setValueExpression("value",
       createValueExpression("#{record.eventDetailArray[" + i +"].detail}", String.class));
       detailColumn = new HtmlColumn();
       detailColumn.getChildren().add(detailText);
       detailsHtmlTable.getChildren().add(detailColumn);
       }
      
      


      my commandlink, that should refresh my table:

      <a4j:commandButton id="addDetailButton" value="add" image="/images/bt0_6.gif"
       action="#{newEvent.addDetail}" reRender="detailsTable"/>
      


      I could add some data to my datable and it is shown, but adding columns is not possible without reloading the whole htmlpage after hiting the commandlink. I also tried to put my datatable in a panelGroup, but its the same problem. any ideas?

      thanks a lot

        • 1. Re: refresh/rerender whole datatable
          ilya_shaikovsky

          make your new event bean request scoped.

          • 2. Re: refresh/rerender whole datatable
            smilidon

            Thanks, but i have still the same problem. Columns added are not shown, until reloading the page.

            • 3. Re: refresh/rerender whole datatable
              hedinant

              Hi Smilidon trying to do it your way.

              There are a function, createValueExpression, may you post how did you implement it.

              I did not find a way.

              May you describe how it works, or give me a good link to read?

              • 4. Re: refresh/rerender whole datatable
                xorsolutions

                Smilidon, maybe you should use something like this?

                <a4j:commandButton id="addDetailButton" value="add" image="/images/bt0_6.gif" action="#{newEvent.addDetail}">
                 <a4j:support event="oncomplete" reRender="detailsTable"/>
                </a4j:commandButton>
                


                In this case rerendering will occure when request will be completed on server side.

                Offtopic. Tell me please, is your application web or enterprise?

                • 5. Re: refresh/rerender whole datatable
                  ilya_shaikovsky

                  XorSolutions, your suggestion is not good. Using your construction - two requests will be fired...

                  • 6. Re: refresh/rerender whole datatable
                    smilidon

                    sure hedinant:

                     private ValueExpression createValueExpression(String valueExpression, Class<?> valueType) {
                     FacesContext facesContext = FacesContext.getCurrentInstance();
                     return facesContext.getApplication().getExpressionFactory().createValueExpression(
                     facesContext.getELContext(), valueExpression, valueType);
                     }
                    


                    you also will find it here, very good blog about datatables:
                    http://balusc.blogspot.com/2006/06/using-datatables.html


                    there is also a spelling mistage, it has to be:

                    <rich:dataTable id="detailsTable" binding="#{newEvent.detailsHtmlTable}">
                     </rich:dataTable>
                    


                    i will try xorsolution code, if it works, it could be a temporary solution

                    regards

                    • 7. Re: refresh/rerender whole datatable
                      hedinant

                      Thanks alot. It works.

                      So if you will find solution to reload problem post it please.

                      Or a more classic way to implement this.

                      • 8. Re: refresh/rerender whole datatable
                        nepveul

                        Smilidon, can you tell me which version of jboss AS, Seam, and richfaces you are using.

                        I'm trying to do something similar, but run into a

                        Component not instance of org.richfaces.component.UIDataTable

                        error.

                        Thanks!

                        • 9. Re: refresh/rerender whole datatable
                          smilidon

                          a little bit late, but i use jboss 4.2.1, richfaces 3.1.3 and no seam.

                          any news about this topic? i'm still looking for a solution to add dynamic columns to a datatable(and it looks like others doing that too).

                          regards

                          • 10. Re: refresh/rerender whole datatable

                            Hi,

                            I think maybe having detailsHtmlTable = new HtmlDataTable(); in your getter causes the problem. You should move the it in the constructor so that it is created during the creation of the bean. By doing so you also have to take care of removing the columns before you add new ones. But this is only necesarry with a session bean I think.

                            Maybe the binding referes to a specific instance, by alway creating a new one it is lost and yaou have to refresh the whole page to renew the binding...


                            I don't know if all that is corrrect, but you could experiment with it ;)

                            Let me know if ot works.

                            I tried it this way and it works for me, meaning I can add and remove columns dynamically

                            • 11. Re: refresh/rerender whole datatable
                              sdelvalle

                              Hi,

                              I was trying to do the same, and finally could. What I did is bind the datatable to a session scoped bean of class HtmlDataTable, and everytime I need to change the columns I get the bean from the session attributes and do all the operations directly on this bean.

                              Hope this helps.


                              Regards

                              Sergio Del Valle

                              • 12. Re: refresh/rerender whole datatable
                                smilidon

                                Hi,

                                StevoFFM or sdelvalle, could you post some code please?

                                thanks in advance

                                S.

                                • 13. Re: refresh/rerender whole datatable
                                  smilidon

                                   

                                  having detailsHtmlTable = new HtmlDataTable(); in your getter causes the problem


                                  thanks a lot, that was the reason.