DimaSan
DimaSan

Reputation: 12684

How to save changes by confirming password

When user updates data on his personal page I want to invoke a confirm dialog with password request to confirm that changes.

Here is my confirm button:

<p:commandButton value="Confirm" update="message" ajax="false" actionListener="#{customerBean.confirmChanges()}">
    <p:confirm header="Confirm changes" icon="ui-icon-alert" message="Please enter your password to confirm changes:"/>
</p:commandButton>

<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
    <p:commandButton value="Submit" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
    <p:commandButton value="Cancel" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
    <p:password value="#{customerBean.currentPassword}" required="true" redisplay="true" label="Current Password"/>
</p:confirmDialog>

And here is the corresponding method:

public String confirmChanges() {
    if (currentPassword.equals(customer.getPassword())) {
        saveCustomer();
        logger.info("\nCustomer updating SUCCESS.", " CustomerID:" + customer.getId());
        addMessage("Updating Success", "Your information was successfully updated.", SEVERITY_INFO);
    }
    addMessage("Updating Error", "Your password is wrong please try again.", SEVERITY_ERROR);
    currentPassword = null;
    return null;
}

Now when I press the "Submit" button the dialog appears but doesn't invoke my method.

Upvotes: 0

Views: 90

Answers (1)

ankush yadav
ankush yadav

Reputation: 422

http://www.primefaces.org/showcase/ui/overlay/confirmDialog.xhtml

conform dialog box is used for take yes or no from use, if you want to take value from user better to use dialog box see refer showcase example

http://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml

This will help you. Use of dialog box is easy.

Upvotes: 1

Related Questions