2 Replies Latest reply on May 7, 2008 6:18 AM by andygibson.contact.andygibson.net

    Refreshing Datamodel

    viniciuscarvalho.viniciusccarvalho.gmail.com

      Hello there! I've seen a good number of people asking this, but haven't seen a clear answer.
      We have a CRUD screen with a datamodel. When the user updates one of the items of the datamodel, the list is not updated. When a new item gets inserted the model is updated.


      Checking the source of the DataModelBinder I found this:



      |public boolean isDirty(DataModel out, javax.faces.model.DataModel wrapper, Object value)
         {
            return !getWrappedData(out, wrapper).equals(value);
         }|



      Well, ok, so It uses the equals method for an arraylist. My Entity class relies on the ID for a correct equals implementation. What if I change the user name? What about the address? The list goes on for each property inside my bean.


      How can I force a refresh on my datamodel? Is it possible?


      Best regards

        • 1. Re: Refreshing Datamodel
          vasana

          Are you using factory or Datemodel annotated methods to populate your table? If so try calling that method explicitly after your update is complete

          • 2. Re: Refreshing Datamodel
            andygibson.contact.andygibson.net

            There's a couple of ways of getting around this problem. The simplest is to clear the datamodel if it is in a shared conversation with the update process.


            Or you can use events to signal to the datamodel that one of the objects has changed and it needs to refreshed.


            If you are using entityHome, then by default, they raise an event whenever you update an item. From the seam documentation :



            org.jboss.seam.afterTransactionSuccess.<name> — called when a transaction succeeds in the Seam
            Application Framework which manages an entity called <name>

            However, raising your own event is simple too.


            The other option is to make the list stateless so it is fetched each time the page is rendered. I'm guessing you don't want to go that route because you want want to use the datamodel and datamodel selection features. The alternative to that is to pass Ids as parameters and use a stateless list that is fetched each time that page is rendered.


            Cheers,


            Andy Gibson