3 Replies Latest reply on Jan 15, 2009 10:09 AM by Ilya Shaikovsky

    richfaces cache of table model: how to avoid it?

    Dmitri Ilyin Newbie

      Hi,

      i use richTable and try to add a new row to it via an action. I have a a4j:commandButton that calls an action. In that action i try to change the table model.

      <a4j:commandButton id="create" action="#{displayableTestBean.create}"
       value="create" reRender="dtTable"/>
      

      for the table i use ExtendedTableDataModel.

      The problem that i have is it seems that richfaces caches the table model in
      "APPLY_REQUEST_VALUES" phase. So that the model changes in
      "INVOKE_APPLICATION" phase just ignored.
      I can see next line in the LOG:
      DEBUG [ExtendedTableDataModel] load data from range: 0 - 12
      It occurs in APPLY_REQUEST_VALUES phase. It seems to me that to this time the model will be cached. ExtendedTableDataModel is changed (or better say the data list under it) in INVOKE_APPLICATION via my action. But i don't see
      "load data from range: 0 - 12" line n the LOG in "RENDER_RESPONSE" phase any more and as a result the table will be just shown in browser with "old" data list.

      How can i avoid caching? or are there any other patterns how change table model should be made?

      thanks for any advise
      regards
      Dmitri


        • 1. Re: richfaces cache of table model: how to avoid it?
          Nick Belaevski Master

          Hello Dmitri,

          Here is the excerpt from UIExtendedDataTable class code:

          /**
           * Original version of this method is defined in
           * {@link org.ajax4jsf.component.UIDataAdaptor} and is called before
           * RENDER_RESPONSE phase. In that version data model is reseted which causes
           * need to sort and filter every time component is rendered.
           */
           // @Override
           protected void resetDataModel() {
           // Do not reset only for ExtendedTableDataModel model
           if (!(getDataModel() instanceof ExtendedTableDataModel<?>)) {
           super.resetDataModel();
           }
           }


          As I can see there's org.richfaces.model.ExtendedTableDataModel#reset() method. Maybe calling it will help?

          • 2. Re: richfaces cache of table model: how to avoid it?
            Dmitri Ilyin Newbie

            Hi,

            thanks.
            We have found a workaround. But i think this problem should have a general solution.

            We have to delete a row. For that i have placed commonadButton in the row. In the apply request the table model is read in order to decode request values and find out which row is to delete.

            After the model is read first time it is cached. After that the model is changed in the action method (the row is deleted), but it is too late. Our workaround is to recreate tablemodel after it is changed in the action method. But it seems to me to be not the best solution.

            ragards
            Dmitri

            • 3. Re: richfaces cache of table model: how to avoid it?
              Ilya Shaikovsky Master

              I've forwarded your question to ExtendedTable authors. Thanks again for your efforts.