Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 874
WheelPot Avatar asked Oct 05 '15 11:10

WheelPot


People also ask

How do I trigger a refresh page?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

How do you refresh a HTML page?

The reload() method reloads the current document. The reload() method does the same as the reload button in your browser.


1 Answers

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());
}
like image 60
Jordi Castilla Avatar answered Oct 10 '22 17:10

Jordi Castilla