3

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>

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
cobaltduck
  • 1,598
  • 5
  • 25
  • 51

1 Answers1

0

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

lkdg
  • 1,031
  • 7
  • 18
  • I assume that "frmMain" is the id of the form? – cobaltduck Mar 08 '11 at 13:08
  • Yes frmMain is the name of my form. – lkdg Mar 09 '11 at 06:03
  • 1
    Technically, this suggestion did not work as written. However, calling a javascript function onclick, where said method set the values in the form to the empty string, i.e. `document.getElementById(subviewId:inputId) = "";` did the trick. (I still call the bean's clear method to clean up some other logic.) So I am accepting this answer. – cobaltduck Mar 24 '11 at 12:17
  • I feel like this is such an inelegant workaround to a really good question that there just must be a better answer. Did you find out anything else? – Lisa Oct 08 '13 at 04:05
  • 1
    @Lisa: I know this probably isn't what you are looking for, but a really good solution a year and half later is to drop-kick Trinidad and use RichFaces or PrimeFaces. Good luck. – cobaltduck Oct 08 '13 at 13:59