How to implement a form reset button in JSF when you have PPR and validators?

cobaltduck picture cobaltduck · Mar 7, 2011 · Viewed 7.6k times · Source

My <tr:form> contains some fields with validators, including <tr:inputDate> whose validator is built-in. I also have some AJAX/PPR going on, with partialTrigger attributes where say, one combo box's choices depend on the choice of an earlier combo box, typing something in one feild disables another field, and so on.

I need a clear/ reset button on this form that does the expected things: remove all form entries, set things to default values, etc.

<tr:resetButton> is patently useless. As soon as even one PPR happens, the button does absolutelty nothing. OTOH, <tr:commandButton text="Clear" action="#{myBean.clear}" /> is treated as a submit by JSF, so validation occurs, that is, if there is even one field on the form where the user has typed invalid data, the error message appears next to that field, and the form is not cleared.

What is my alternative? Is there a way to bypass the lifecycle and submit without validation for this button? I would move my validation to the backing bean, but I can't do so for the <tr:inputDate>

Answer

lkdg picture lkdg · Mar 8, 2011

this works in my case:

<tr:commandButton text="reset" onclick="javascript:document.frmMain.reset();"
immediate="true" action="#{myBean.clear}"></tr:commandButton>

but not if I set partialSubmit="true". Regards