How to redirect to the same page after POST request

How to redirect to the same page (I don’t know the page, redirection is performed inside a menu shared by several pages)?

I tried

return "?faces-redirect=true"; 

at the end of the action method, but I got an error because it was not possible to find a navigation case for "? faces-redirect = true".

Thanks in advance for your help.

+8
jsf-2
source share
2 answers

You need to specify a valid view identifier in the results, not just the query string. You can get the current identifier of the form UIViewRoot#getViewId() .

 String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId(); return viewId + "?faces-redirect=true"; 
+18
source share

Just return null or empty string from your application action.

According to the JSF2.2 specification, section 7.4.1:

If the result returned by the application action is null or an empty string , and none of the navigation cases displaying the current view identifier has an expression other than zero, the same representation should be re-displayed.

-one
source share

All Articles