Page reload with JSF faces-config.xml navigation rules

von tobonaut

To reload / refresh the current page via a navigation case, you have to provide the current view id in a related backing bean…

   public String getCurrentViewId()
   {
        return FacesContext.getCurrentInstance().getViewRoot().getViewId();
   }

… add this to the ** parameter of a navigation case in your faces-config.xml.

<navigation-case>
    <from-action>#{myBean.doSomething}</from-action>
    <from-outcome>SUCCESS</from-outcome>
    <to-view-id>#{myOtherBean.currentViewId}</to-view-id>
    <redirect/>
</navigation-case>

That’s pretty nice and simple snippet which helps you to prevent the usage of javascript calls like window.location.reload().

Advertisements