0

I have a primefaces calendar with a validator attached to it.

<p:calendar id="validationTriggeringCalendar"
            label="other calendar"
            value="#{myBean.otherDate}"
            navigator="true"
            locale="de"
            pattern="dd.MM.yyyy"
            showOn="button"
            renderAsPopup="true"
            required="true"
            size="12">
    <f:validator validatorId="packagename.DateFromToValidator" />
</p:calendar>
<p:calendar id="myCalendar"
            label="Some Date"
            value="#{myBean.someDate}"
            navigator="true"
            effect=""
            locale="de"
            pattern="dd.MM.yyyy"
            showOn="button"
            renderAsPopup="true"
            mindate="#{myBean.mindate}"
            size="12">
</p:calendar>

Inside the validator I get the calendar UI component myCalendar(the one that did not trigger the validation) and call the getValue() method, which does not return the value that is entered into it.

I debugged the validator code entering the date "10.10.2009":

UIInput calendar = getMeTheCalendar();
Date date = (Date) calendar.getValue();

My debugger even tells me the value of the submittedValue attribute of the calendar is "10.10.2009", exactly what I entered and what is displayed in my browser. But the getValue() method returns a date object Thu Oct 10 00:00:00 CEST 2019.
How do I get the entered value of the component?

I use Primefaces 5.3.1 btw.

David
  • 1,672
  • 2
  • 13
  • 32
  • While debugging, what does the third parameter of your `validate` method tell you? The Calendar.getValue() will return the entered date when models have been update **after** the successful validation phase. – Selaron Jun 21 '19 at 12:29
  • Ok, but how can I validate the input, if it is just accessible by the validator after validation? – David Jun 21 '19 at 12:31
  • Are you sure `myCalendar` is **above** the validated calendar? Looks like element order matters: [jsf validate two fields in one time](https://stackoverflow.com/questions/3478133/jsf-validate-two-fields-in-one-time) – Selaron Jun 21 '19 at 12:55
  • No the calendar, that triggers the validation is `validationTriggeringCalendar`. But I lookup `myCalendar` by its id and try to get its value. – David Jun 21 '19 at 12:59
  • Possible duplicate of [JSF doesn't support cross-field validation, is there a workaround?](https://stackoverflow.com/questions/6282466/jsf-doesnt-support-cross-field-validation-is-there-a-workaround) – Selaron Jun 21 '19 at 12:59
  • 1
    Yes I understand that - when looking at your example code, your `myCalendar` is declared above the validated `validationTriggeringCalendar`. Is that also true for the source code in your actual application you see in your IDE? If so, myCalendar.getValue() **should** return the entered value as it can be read in [this answer](https://stackoverflow.com/a/3478409/865107). – Selaron Jun 21 '19 at 13:03
  • No the order of the two calendars is changed: the `myCalendar` is actually declared above the `validationTriggeringCalendar`. I'm gonna correct this. – David Jun 21 '19 at 13:18
  • So then you basically know how to solve this, right? – Selaron Jun 24 '19 at 07:05
  • Yes, the hint with the order of declaration and the link for the possible duplicate gave me the right direction, that there is a getSubmittedValue() method and which method to use in what case. – David Jun 24 '19 at 07:56

0 Answers0