4 Replies Latest reply on Aug 1, 2006 7:59 AM by hdslkf hklsdg

    How to update @DataModel and its ListDataModel?

    hdslkf hklsdg Apprentice

      I have an Entity Person (my favorite example *g*) and a page that lists all instances.

      Here are some code snippets, believe me, it's simple ;).

      The class delivering the list:

      @Stateful @Scope(ScopeType.SESSION) @Name("personList")
      public class ....
       private List<Person> persons;
       public void loadList() {
       person = em.createQuery("from Person");
       log.info("Persons are: " + persons);

      The JSF:
      <h:dataTable var="person" value="#{persons}">

      Well, whenever a person is changed, added or deleted, the "personChanged" event is fired. This works perfectly, since the log always shows that really the newest state of all persons has been fetched from the database. If I just changed "John Doe" to "John Sixpack" then the change is shown in the persons variable immediately.

      BUT: The underlying ListDataModel (@DataModel wraps the java.util.List into a org.jboss.seam.jsf.ListDataModel) is only up to date after deleting or adding a Person, namely changing the number of all entries. If I change an existing Person then the ListDataModel doesn't change and the overview page shows the old status.

      So the List is up to date, the ListDataModel isn't (I found this out by adding a toString() method to ListDataModel that shows the wrapped data und outputting it via <h:outputText value="#{persons}" />).

      * How can I tell the ListDataModel that it should update its wrapped data?
      * Why does this only work automatically when changing the length of a list? (I'm curious ;))