Search code examples
jsfprimefacesview-scope

Primefaces ViewScoped


I want my managed bean to be cleared after a successful action. I use PrimeFaces5.0 for web page. Here is a block. I used partialSubmit and process to submit only one part of the form.

<p:panel id="panel1">
  ...
    <p:commandButton id="saveButton" value="Save"
        action="#{myBean.save}" 
        update="msg" partialSubmit="true" process="panel1" />
</p:panel>

I used @viewScoped for managed bean and my save method is

public String save() {
    //do some save stuff
    try{
        myEjb.save();
        return "";
    } catch (EJBException ejbe) {
        mesajYazKaydetmeHatali(ejbe);
        ejbe.printStackTrace();
    }
    return null;
 }

Although I return "" after a successful save, I think PF does not refresh the page. How can I achieve this.

Thanks


Solution

  • instead of returning an empty string, you can redirect the user to the same page in case of successful save:

    FacesContext.getCurrentInstance().getExternalContext().redirect(redirectionPath‌​);