capitano666
capitano666

Reputation: 656

Ajax-enabled confirm in richfaces?

I need some help with richfaces. Here's what I need to do in pseudocode:

//user clicked on a <h:selectBooleanCheckbox/>
if(!checkbox.checked) {
    ajax_call_method0_on_bean
    return
}
else {
    boolean_value = ajax_call_method1_on_bean
    if(boolean_value == true) show_confirm
        if(confirm_result == false) return

    //if(boolean_value == false OR confirm_result == false)
    ajax_call_method0_on_bean
}

Basically I have a checkbox which, when clicked to uncheck, first has to verify if a confirmation box must be shown, then (if no confirmation was needed or confirmation was ok) call the final action

Upvotes: 0

Views: 2701

Answers (1)

Ken Chan
Ken Chan

Reputation: 90497

Some important points :

1 . You can use the <rich:modalPanel> to define the confirm popup . Inside the confirm popup , a OK button will call beans 's doFinalAction()

<rich:modalPanel id="confirmPopUp" width="350" height="100">
        <f:facet name="header"> Confirm popup</f:facet>
            <a4j:commandButton value="OK"  action="#{bean.doFinalAction}" />
            <br />
            <a4j:commandButton value="Close"  onclick="#{rich:component('confirmPopUp')}.hide()"/>
</rich:modalPanel>

2 . You can use <a4j:jsFunction> to define a javascript function that will invoke a beans ' method to check if the confirmation box is required to show up . This method 's responsibility is to set a boolean flag (bean.requireConfirm) to true if the confirmation is required . Otherwise , execute doFinalAction().

<a4j:jsFunction name="checkRequireConfirm" 
                action="#{bean.checkRequireConfirm}"
                oncomplete=" if (#{bean.requireConfirm}) {#{rich:component('confirmPopUp')}.show()}">
</a4j:jsFunction>

Check bean.requireConfirm in the oncomplete attribute .Show the confirmation popup if it is true.

3 . Add an onclick event handler to the <h:selectBooleanCheckbox> , which calls the JS checkRequireConfirm() defined in (2) if the check box is unchecked

<h:selectBooleanCheckbox  onclick="if (!this.checked){checkRequireConfirm()}"/>

Upvotes: 1

Related Questions