3 Replies Latest reply on Jan 13, 2010 12:58 PM by Leo van den berg

    Refresh problem

    Ercan  Isık Newbie

      Hi all. I made and CRUD aplication on Seam.I am uain data table to show registered user and  near every user there is button to delete this user.It works well but when I press on console i can see that it deletes but on page it doesnt delete .after pressing F5 and refreshing it shows me that this user not more exist.but I want to make it when I press delete button it must refersh automaticliy.how can i do it? on reme() function I must recall  list?

        • 1. Re: Refresh problem
          Tamas Malatinszki Newbie

          You can refresh Your datatable using reRender option of Your delete button, but It will show the original list, so You need to:



          • delete the user

          • refresh the list

          • refresh the datatable with the reRender function




          Regards,


          Tamas

          • 2. Re: Refresh problem
            Ercan  Isık Newbie

            I must use this reRender on xhtml  page? and how can I refresh list? recaling it?

            • 3. Re: Refresh problem
              Leo van den berg Master

              Hi,


              Seam has some nice feautures to automate the process substantially, so you don't need to worry too much..


              You have the status of the DB and the status of your screen to consider. I assume you have solved the problem of deleting the user. The other part is where you need to reload the list and reRender. The easiets way is to use an Ajax-enabled submit, by means of a ajax-supprt tag INSIDE your standard sumbit button, or a Ajax-button. Look at the Rich-faces (I assume you are using that..) documentation how to do that.


              The following is a piece of JSF where the button which fires an action an closes a popup window after finishing the action :


               <a4j:commandButton 
                      value="SAVE"
                   action="#{userManagementAction.finish}" 
                      eventsQueue="inputQueue"
                   onclick="#{rich:component('userManagementModalPanel')}.hide();" />



              You can also do the reRender stuff incombination with an action. Clicking the link selects a specific user (see the use of parametrized EL!!) and reRender a part of the view.


              <a4j:commandLink 
                      value="#{_user.fullName}"
                   action="#{userManagementAction.selectUser(_user)}" 
                   eventsQueue="inputQueue"
                   reRender="userDetails, userText"/>
              



              After making changes in the Database you need to read the user list from the database.I use an APPLICATION-SCOPED component which caches the users for the whole application. Please be aware that different sessions can access this component, so make accessing the userList a synchronized method.


              ....
              
              @Unwrap
              public synchronized List<User> getUsers(){ 
                 return users;
              }
              ....     
              @Observer(value={"whatever.userUpdateEvent"})
              @RaiseEvent("a.refreshe.event")
              @SuppressWarnings("unchecked")
              @Transactional
              public synchronized void readUsers(){
                 users = entityManager.createQuery(queryString).getResultList();
                 log.info("Caching " + users.size() + " Users ");
                 events.raiseAsynchronousEvent();
              }
              ....
              



              I use events to trigger the reading of the database and informing other components of this refresh (hence the observer and raiseevent annotations). The unwarap annotation is a nice Seam-trick to return whatever object from referencing its surrounding component. So if you give the component the name whatever; a reference to it in another bean will be:



              protected List<User> whatever;
              


              So basically:





              • Write a caching user list seam bean

              • Write the edit bean and add events leading to refreshing the previous bean after doing something,

              • Add a ajax button to your screen

              • Use the bean UNWRAP name for your datatable

              • ReRender the table after you do something



              be aware that things are synchronized no, so it will have an impact on you performance if you have a high number of users accessing this code you should try another concept.


              Hopefully this helps.



              Leo