1

I'm trying to use validateOrder component to validate two java.util.Date objects. It is similar to showcase example on this link (PrimeFaces example). Everything works perfect, but i have one question:

What if 2nd date field is not required?

In that case i'm getting nullpointer exception, and since validateOrder has "disabled" attribute, i was wondering is it worth/possible enabling/disabling it via ajax every time the 2nd date is inserted/removed. If not, i guess i'll stick to Balus' approach for JSF2.0 cross-field validation that you can read about on this link.

Community
  • 1
  • 1
Nikola
  • 554
  • 1
  • 4
  • 20

1 Answers1

1

Let the disabled attribute check if the 2nd field is filled in. If it's not filled in, the request parameter value associated with field's client ID will be empty. Use exaclty that to let disabled attribute evaluate to true.

<p:calendar ... binding="#{endDate}" />
...
<o:validateOrder ... disabled="#{empty param[endDate.clientId]}" />

Code is as-is. No additional backing bean property necessary for binding.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks Balus. This solution seems to work with "plain" inputs, like h:inputText. I had problem with p:calendar because it is rendered as input field surrounded with span. If calendar's id is set to let's say "calId", then input's id is automaticly generated as "form1:calId_input", while span's client id is "form1:calId". – Nikola Jan 05 '14 at 05:25
  • **Continued** So instead of `disabled="#{empty param[endDate.clientId]}"` i had to use `disabled="#{empty param['form1:calId_input']}"` (and ignore Eclipse warning that this expression always evaluates to false). Anyway, generaly speaking realy nice solution, ty again. – Nikola Jan 05 '14 at 05:37