1

Since there's no attribute/option for <p:calendar> (readonlyInput="true") to reset the value to null, the best available solution currently is to use some client JS to reset the value like here:

https://stackoverflow.com/a/12325640/396732

However, as soon as the clear button controls an AJAX button, the new calendar value isn't submitted.

I tried to process the end-date button, like:

                <p:calendar id="end-date"
                            widgetVar="myEntityEndDate"
                            value="#{myEntityManager.selectedEndDate}"
                            readonlyInput="true"
                            showOn="button">
                    <!-- update dependent "begin" calendar component: -->
                    <p:ajax event="dateSelect" process="@this" update="begin-date" />
                </p:calendar>
                <p:commandButton icon="ui-icon ui-icon-close"
                                 onclick="myEntityEndDate.setDate(null);"
                                 process="end-date"
                                 update="begin-date end-date" />

However it isn't working...

Q:

How do you implement a reset button for an AJAXed p:calendar component?

Addendum:

The same question was asked here: http://forum.primefaces.org/viewtopic.php?f=3&t=27821 . It seems like jQuery could be the "guilty party". Anyways, it should be solved/solvable IMHO.

Community
  • 1
  • 1
Kawu
  • 13,647
  • 34
  • 123
  • 195
  • you can use `oncomplete` instead of `onclick`, like `oncomplete="myEntityEndDate.setDate(null);`. Or just set the bean value itself to null. If you want the previous value instead of null you can use ``. – fischermatte Jan 09 '13 at 16:42
  • But isn't oncomplete executed *after* the AJAX request was processed? The problem I see is that there is no AJAX request at all... – Kawu Jan 10 '13 at 09:56
  • @Kawu. if you want a client side only operation , than try to change your button into this : `` – Daniel Jan 10 '13 at 09:59
  • yes it will be executed after the request was sent. depends what you want. do you just want the end date on server site set to null? in this case you could just use `` for your commandbutton and set the end date to null. – fischermatte Jan 10 '13 at 10:04
  • @Daniel: I want the operation to be processed to the server as well. I had hoped it will be automatic, but it seems the reset buttons for AJAX inputs have to deliver that functionality manually, e.g. via an action listener (as suggested by fischermatte). – Kawu Jan 10 '13 at 10:07
  • Of course, an `` will perform the server operation! (where has my mind been? duh) @fischermatte: please post this as an answer and I'll accept it. – Kawu Jan 10 '13 at 10:30

1 Answers1

1

If you want the reset will be reflected on the server you should use the action of p:commandButton

<p:commandButton icon="ui-icon ui-icon-close"
    action="#{myEntityManager.resetDate}"
    process="end-date"
    update="begin-date end-date" />


public void resetDate(){
    selectedEndDate = null;
}
Daniel
  • 36,833
  • 10
  • 119
  • 200