Display name
Display name

Reputation: 41

Is it possible to refresh a page through ajax in JSF?

I have something like this :

<h:commandButton action="#{MyBean.action()}">
   <f:ajax render ="@all"/>
</h:commandButton>

Is it possible to replace the "@all" in the ajax render to refresh the page?

Upvotes: 3

Views: 4270

Answers (1)

BalusC
BalusC

Reputation: 1108577

With this code my page doesn't refresh like if I press F5

That's not possible with ajax. Just remove <f:ajax> and send a redirect to self in action method.

<h:commandButton value="Submit and refresh" action="#{bean.action}" />
public String action() {
    // ...
    FacesContext context = FacesContext.getCurrentInstance();
    return context.getViewRoot().getViewId() + "?faces-redirect=true";
}

Or if you actually don't need to perform a business action, just use <h:button> without an outcome.

<h:button value="Refresh only" />

Upvotes: 3

Related Questions