3

I want to disable other input tag if p:calendar value is entered

  <p:calendar id="someDate" value=.... binding="#{bind}" />

for example to disable p:selectOneMenu but this disables it permanently.

 <p:selectOneMenu id="selectManu" value=... disabled="#{bind!=null}" >

How to disable it only if p:calendar have value ??

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • You may want to go with what is said to be *cross field validation* but where do you need this kind of unusual requirement? – Tiny Apr 14 '15 at 12:17

1 Answers1

2

Let the source component ajax-update the target component on the desired events, and let the disabled attribute of the target component check if the value of the source component is not empty.

So,

<p:calendar ... value="#{bean.date}">
    <p:ajax event="valueChange" update="menu" />
    <p:ajax event="dateSelect" update="menu" />
</p:calendar>
...
<p:selectOneMenu id="menu" ... disabled="#{not empty bean.date}" />

The binding is not necessary in this construct. If you really want to use it, then you should be checking the component's value attribute, not the component itself (which is obviously never null).

<p:calendar binding="#{calendar}" ...>
    <p:ajax event="valueChange" update="menu" />
    <p:ajax event="dateSelect" update="menu" />
</p:calendar>
...
<p:selectOneMenu id="menu" ... disabled="#{not empty calendar.value}" />

If you want to learn more about binding, head to How does the 'binding' attribute work in JSF? When and how should it be used?

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452