h:commandButton to cancel sending a form (without validation)

Sometimes the problem with validators is that you can’t send a cancel button from within a form, because the validator stops processing it. In this case it is usefull to set the button on immediate=”true”, but then the problem might be that the view ist not correctly cleared. To force clearing the view, it is important to navigate with an outcome other than null (”").

    <h:commandButton immediate="true"
        actionListener="#{bean.discardEditing}"
        value="#{msg.action_cancel}" />

In the example “bean.discardEditing” does some cleanup and returns a navigation outcome to navigate to the same screen again, e.g. “revertToEdit”.

See also:

Tags:

Leave a Reply