WheelPot
WheelPot

Reputation: 307

How to reload page when a button is clicked?

I need to refresh current page when confirm button is clicked. I am trying to find the answer on the internet, but with little or no success at all. It would be nice if there was a way to update it from front-end (JSF), not from backing bean, but, I will take both answers as solutions.

My command button looks like this:

<a4j:commandButton id="deleteButton" styleClass="simpleButtonRed"
        value="#{msg['common.delete']}"
        execute="@this" render="@none" limitRender="true" >
        <adn:confirm
            id="confirmButtonas"    
            message="#{msg['common.delete.confirm']}"
            confirmAction="#{messagesListBean.deleteMessages}"
            confirmLabel="#{msg['common.confirm']}"
            confirmBtnStyleClass="mainButtonGreen"
            confirmImmediate="true" 
            confirmRender="errorMessageOuterPanel" 
            onConfirmComplete="if(#{!messagesListBean.operationCompleted}) {
                               #{rich:component('errorPanel')}.show();}"/>
</a4j:commandButton>

Upvotes: 17

Views: 64800

Answers (2)

Vasil Lukach
Vasil Lukach

Reputation: 3728

You can use render attribute of a4j:commandButton for this purpose. Example:

<a4j:commandButton value="buttonName"
    action="#{bean.action}"
    render="someForm" />

In your code change render="@none" to render="@form" or render="@all".

Upvotes: 2

Jordi Castilla
Jordi Castilla

Reputation: 26961

You can use javascript

location.reload();

Or you can redirect to same URI as in this answer.

First change commandButton to call bean method:

onConfirmComplete="#{messagesListBean.reload}"

And in the bean:

public void reload() throws IOException {
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    ec.redirect(((HttpServletRequest) ec.getRequest()).getRequestURI());
}

Upvotes: 27

Related Questions