Command button without ajax invokes @PostConstruct on second click

660 views Asked by At

I have a page with few buttons one of which is used to generate and download (show download popup window) excel stylesheet. Ajax is set to ajax=false on a <p:commandButton> because with ajax enabled the download window was not showing.
Button validates if user did everything to be able to download excel and if not then it updates message area showing error popup message through primefaces<p:growl>.
My problem is with button being clicked for second time. After first click, if the validation method resolves to false, the error message is showing without any problems but after a second click the method is not being invoked at all and the @PostConstruct initialize method is invoked so the whole page reloads thus clearing all user inputs.

Here's .xhtml file piece of code:

<p:commandButton styleClass="aqua-button btn-style"
        actionListener="#{symulujHarmonogramSplat.downloadSchedule}"
        update="messages" ajax="false"
        value='#{activePreferencesBean.portletResourcesProvider["view.label.button.downloadSchedule"]}'></p:commandButton>

Here's code of backing bean:

@ManagedBean(name = "symulujHarmonogramSplat")
@ExpireWithPageFlow
@SessionScoped
public class SymulujHarmonogramSplat {
    /**
     * Action button handler - DownloadSchedule
     */
    public void downloadSchedule() {
        log.info(getClass().getName() + ": downloadSchedule() invoked !");
        if (screenLogic.isAllowToDownloadSchedule()) {
            xlsManager.downloadSchedule(applicationData,
                    loanData.getCalculateFinancialDetailsData().getInstallmentList(),
                    loanData.getCalculateFinancialDetailsData());
        }
    }
}

The bean's method downloadSchedule() calls another bean's method screenLogic.isAllowToDownloadSchedule().
Here's code for second bean:

@SessionScoped
@ExpireWithPageFlow
@ManagedBean(name = "symulujHarmonogramSplatLogic")
public class SymulujHarmonogramSplatLogic {
    public boolean isAllowToDownloadSchedule() {
        if (!isSimCompleted) {
            FacesContext.getCurrentInstance().addMessage(null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR, "Nie wykonano symulacji.", ""));
            return false;
        } else {
            return true;
        }
    }
}

Second bean checks if user completed required action and returns true or shows error message accordingly.
My question is what could I do do prevent page to initialize itself after second click (so enforce to invoke actionListener method for each subsequent call).

Edit 1: It doesn't matter if backing bean's method actually do anything (show message for that matter) or not. If after page reloads after first click I click it second time it always invokes PostConstruct init.

0

There are 0 answers