开发者

JSF - No reload content

folks! I have a table in JSF <h:dataTable> but when I create a new Object (with JPA forward) in my table sometimes it´s shows but sometimes not. I must click in a tab to recharge the content of the xhtml because the开发者_高级运维 new element isn´t shown. Could I reload the page after adding the Object to the list from the backing bean?

Thanks for reading and sorry for my english.


you can't control the page from the backing bean except total reload, but if you creates new object on some action, for example a button click, then you can do the following using ajax:

<h:commandButton actionListener="#{bean.addNewObject}" value="Add">
  <f:ajax execute="@this" render="tableId" event="click" />
</h:commandButton>

If you don't want to use ajax and reload the whole page, then use action param of the commandButton:

<h:commandButton action="#{bean.addNewObjectAction()}" value="Add"/>

where addNewObjectAction returns null to reload the page.


Apparently you're storing the list of items for the datatable in the session scope and not reloading it whenever a new item is added. You need to reload it in the action method of adding new item.

public void add() {
    saveNewItemInDB(newItem);
    items = reloadListOfItemsFromDB();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜