5 Replies Latest reply on Mar 11, 2008 5:41 PM by jamesjmp

    updates and refresh

      hi,
      After updating some entity values in a page I redirect to the list of that entities.
      First time the list page is displayed, there are some values that are not properly up to date. If I log out and then log in the values in that list are ok.
      I´ve tried to force to refresh the list by means of adding this to my components.xml:


         <event type="org.jboss.seam.afterTransactionSuccess.Firm">
              <action execute="#{firmList.refresh}" />
          </event>       
      



      This event and refresh works ok when I persist and remove. Howewer it does not refresh my list first time after updating.


      On the other hand I´ve added this to the pojolist.page.xml to  refresh:


      <action execute="#{firmList.refresh}"/>
      



      Once the redirection has been done, it only displays proper values after pressing F5


      any idea to refresh the list before displaying the list page?
      btw, I´m using Seam 2.0.1.GA with JBoss 4.2.2 and not EJBs, just POJOs.
      thanks in advance!



          

        • 1. Re: updates and refresh
          pmuir

          Jaime Martin wrote on Mar 11, 2008 01:35 PM:


          hi,
          After updating some entity values in a page I redirect to the list of that entities.
          First time the list page is displayed, there are some values that are not properly up to date. If I log out and then log in the values in that list are ok.
          I´ve tried to force to refresh the list by means of adding this to my components.xml:

             <event type="org.jboss.seam.afterTransactionSuccess.Firm">
                  <action execute="#{firmList.refresh}" />
              </event>       
          



          This event and refresh works ok when I persist and remove. Howewer it does not refresh my list first time after updating.

            


          The event should be called on an entityHome.update() - so I suspect there is some other caching e.g. in the persistence context.

          • 2. Re: updates and refresh

            Is the underlying list in your action that is backing the component seeing the changes?


            ie:  is it a view thing? or is the underlying entity in the Action not actually changed?

            • 3. Re: updates and refresh

              Hi, this is my update Method and in FirmHome.java


                 
              @Name("firmHome")
              public class FirmHome extends EntityHome<Firm> {
                        
                  @In(create = true) @Out
                  FirmList firmList;    
                  ....
                  
                  @Override
                  @SuppressWarnings("unchecked")
                      @Transactional
                  public String update() {    
                      EntityQuery cfgCurrencyIsoSugQuery = (EntityQuery) Component.getInstance("CfgCurrencyNoRestrict");
                      String rest = "lower(cfgCurrency.currencyIso) like concat(lower(#{'" + this.getInstance().getCfgCurrency().getCurrencyIso() + "'}),'%')";
              
                      List<String> restrics = new ArrayList();
                      restrics.add(rest);
                      cfgCurrencyIsoSugQuery.setRestrictions(restrics);
                      List sugCurrency = cfgCurrencyIsoSugQuery.getResultList();
              
                      ArrayList result = new ArrayList();
                      Iterator<CfgCurrency> ccyIter = sugCurrency.iterator();
                      CfgCurrency currency = null;
                      while ((ccyIter != null) && (ccyIter.hasNext())) {
                          currency = ccyIter.next();
                          result.add(currency);
                      }
                      this.getInstance().setCfgCurrency(currency);
              
                      try {
                          Query updateQ = this.getEntityManager().createQuery("update Firm f set f.cfgCurrency.currencyCode = :newCcy , f.firmDescription = :newDescrip where f.firmCode = :fcode");
                          updateQ.setParameter("newCcy", currency.getCurrencyCode());
                          updateQ.setParameter("newDescrip", this.getInstance().getFirmDescription());
                          updateQ.setParameter("fcode", this.getInstance().getFirmCode());
                          updateQ.executeUpdate();
              
                      } catch (Exception ex) {
                          log.info("FIRM ex.getMessage!!" + ex.getMessage());
                          ex.printStackTrace();
                      }
                      listFirm();
              }
              
                  
                  public void listFirm() {
                      firmList.refresh();
                      Contexts.removeFromAllContexts("firmList");
                      Redirect.instance().setViewId("/FirmList.xhtml");
                      Redirect.instance().execute();
                  }
              



              And this trying to redirect from page.xml


                 <navigation from-action="#{firmHome.update}">
                     <end-conversation/>
                     <redirect view-id="/FirmList.xhtml"/>
                 </navigation>    
               


               
                In the database I check that updates have been done, and redirection is done as well. But again, when FirmList.xhtml is displayed
                it doesn´t refresh properly some values, only after pressing F5.
               
              I don´t find what is it I´m doing wrong ;-(.
              Any idea?

              • 4. Re: updates and refresh

                hmm....you're using hibernate like it was straight sql.  Some thoughts:


                1)  You probably shouldn't be doing the executeUpdate manually..you should just be updating the entity directly and then letting hibernate do the update.


                2) if you can't do that, take a look at hibernate.clear() to clear out hibernate's session cache so it can reload the entities with your new values.

                • 5. Re: updates and refresh

                  Marcus, about what you have said.
                  1) I tried first with super.update(); but hibernate logs showed it was trying to do 2 update operations:


                  12:28:14,684 INFO  [STDOUT] Hibernate: 
                      update
                          prisk.dbo.FIRM 
                      set
                          firm_ccy_code=?,
                          firm_description=? 
                      where
                          firm_code=?
                  12:28:14,700 INFO  [STDOUT] Hibernate: 
                      update
                          prisk.dbo.CFG_CURRENCY 
                      set
                          currency_iso=?,
                          currency_des=? 
                      where
                          currency_code=?
                  


                  and that was not needed. CfgCurrency is a property of Firm, but it has not to be updated. Maybe I could do this decoupling, but I wanted to give a try to HQL.
                  That is why I made my own update method. It works according to the database, and hibernate log shows this (exactly what I want with this operation)


                  12:36:00,762 INFO  [STDOUT] Hibernate: 
                      update
                          prisk.dbo.FIRM 
                      set
                          firm_ccy_code=?,
                          firm_description=? 
                      where
                          firm_code=?
                  



                  2) You are right, as I am using HQL I need to clear, so I have added:


                  this.getEntityManager().clear();
                  



                  and now id works!!
                  I thought that using refresh() was enough, but I see it is not in this situation.
                  thank you very much Marcus!!