tags:

views:

1787

answers:

4

I have a page where a user enters data and hits a "save" button. The data gets saved to the db, and I want the page to refrsh itself to reflect the new data in the db. I am using a managed bean, how do i get the page to refresh on its own?

A: 

There are two options which come to my mind:

  1. Make use of JSF navigation rules
  2. Use the rendered attributes

ad 1)

Define a page to which you'll navigate to after hitting "save". For doing that, your action for actually saving the data to DB will go into the method defined as an actionListener or, if you want to make your next page depending on the outcome of the saving process, as action.

Navigation rules will be defined in faces-config.xml If no navigation rule matches a given action, the current page will be redisplayed (although from the experience i made this refresh is different to a common HTML refresh).

ad 2)

If you've some lists or a data table on the same page set to a model in your bean, changes will automatically be displayed except you're using the immediate keyword set to true on your save button.

Additionally you might consider a panel with a content of your choice which has the rendered property set to a boolean in your bean, which will be triggered within the saving process and therefore let the content be displayed only after hitting save.

Gerhard Dinhof
+1  A: 

You can make use of the AJAX push feature of IceFaces. This initializes a re-render of the client.

The recommended (and easiest) way is to use the SessionRender API in your managed bean:

SessionRenderer.addCurrentSession("myGroup");
SessionRenderer.render("myGroup");

Consult the Icefaces developers guide for more information.

Sylar
A: 

It depends on how you do it.

When you click the button, the JSF life-cycle is kicked off, if you kick off the save to the database within the button's action, whatever values you update in your manage bean should be reflected in the page automagically. The JSF lifecycle does this for you automatically and icefaces can do it using the AJAX bridge so you won't be required to do a page reload.

If you're doing work asynchronously, you'll need to use the Push API icefaces provides you. To kick off the life-cycle from the server end.

David Ortiz
A: 

Como puedo actualizar mis datos si los elimino con un boton eliminar en la misma pagina esta la tabla y no se actualiza y en la base ya no esta tengo que volver a cargar la pagina y se realiza el cambio. en el prerender de la pagina le puse un get a mi data provider en este caso los guardo en getSessionBean1.getListaLocalidades() pero no pasa nada alguien me puede ayudar trabajo con hibernate ,mysql e icefaces

Javier