Why is the jsf view not updating after loading new data into the backup bean from the database?

I - unfortunately - work with jsf and I have a problem. I have a jsf page that displays a table with some data using a component <h:dataTable>. Each row of this table has <h:commandLink>a "Delete" action to remove an item in this row. When I perform this action, the method in the reverse bean is correctly called, the ArrayList that contains the elements of the table is displayed correctly, and the navigation method returns to the same page where the table is located, it is executed correctly.

But , when the page reloads, the table does not refresh . I see the same elements that were in the table before the delete action.

If I reload the page, now the table is updated.

It seems that the view is being visualized before the bean support has completed its updates.

How to make visualization of a view only when the bean backup has completed the update?

Here is the code:

Command line on jsf page, inside dataTable:

<h:column>
<f:facet name="header">
    <h:outputText value="Rimuovi" />
</f:facet>
<h:commandLink action="#{servicesListBean.removeServizio}" title="Rimuovi questo servizio" onclick="if(!confirm('Vuoi davvero rimuovere questo servizio?')) return false">
    <h:outputText value="Rimuovi" />
</h:commandLink>
</h:column>

And here is the method in the bean base:

public String removeServizio() {
        this.servizioToRemove = (Servizio) getDataTable().getRowData();
        try {
        ServiziDAO.removeServizio(this.servizioToRemove.getId());
        } catch (Exception e) {
            // ...
        }

        return userSessionBean.goToElencoServizi(); 
    }

In this case, I have provided a request scope for bean support. I already tried to provide its session scope and call the method to update the list, but the result is the same.

I hope I was clear enough. Thanks to everyone in advance.


UPDATE THIS QUESTION WHAT CHANGES EVERYTHING

Thanks to everyone. As McDowell said, the problem was not at the time the visualization was rendered, and the problem was not at all in the JSF.

, , , . , , , , System.currentTimiMillis(), , , sysdate Oracle.

, , : !

, - .

+3
2

, , bean .

, , - , , .

, bean. ListBean? :

  • HTTP POST
  • RESTORE VIEW ListBean ( )
  • servicesListBean bean
  • INVOKE APPLICATION, removeServizio() , bean
  • RENDER RESPONSE bean
  • , bean ,

bean :

public class DeleteFromRowBean {

  private ListDataModel dataModel;

  public DataModel getList() {
    if (dataModel == null) {
      List<RowBean> list = PersistenceStore.fetch();
      dataModel = new ListDataModel(list);
    }
    return dataModel;
  }

  public String deleteCurrentRow() {
    if (dataModel == null) {
      throw new IllegalStateException();
    }
    RowBean row = (RowBean) dataModel.getRowData();
    PersistenceStore.delete(row.getId());
    return null; // no navigation required
  }

}

( ). bean - . INVOKE APPLICATION; RENDER RESPONSE getList(), .

public class DeleteFromRowBean {

  private ListDataModel dataModel;

  public DataModel getList() {
    if (dataModel == null) {
      List<RowBean> list = PersistenceStore.fetch();
      dataModel = new ListDataModel(list);
    }
    return dataModel;
  }

  public String deleteCurrentRow() {
    if (dataModel == null) {
      throw new IllegalStateException();
    }
    RowBean row = (RowBean) dataModel.getRowData();
    PersistenceStore.delete(row.getId());
    // flush cached data
    dataModel = null;
    return null; // no navigation required
  }

}
+4

"" ( ), . . - :

public String removeServizio() {
    .
    .
    .
    userSessionBean.goToElencoServizi(); // if this redirects to needed page
    return null;
}
+1

Source: https://habr.com/ru/post/1706173/


All Articles