Forum Stats

  • 3,750,457 Users
  • 2,250,181 Discussions
  • 7,866,986 Comments

Discussions

Dynamically set required on UI Element

ChristianM0147
ChristianM0147 Member Posts: 18 Red Ribbon

Hello!

Is there a way to dynamically set the required attribute on a UI component based on another UI Component? I have a <af:inputDate> and a <af:selectBooleanCheckbox> Component and one of those two Components have to have a value. And only one of them may have a value.

The use case is that the user has to enter a date or explicitly say that he doesnt know the date via <af:selectBooleanCheckbox>.

I tried to achieve this using the Expression Builder #{empty bean.bindingDate.value} but it does not work properly.

Any help is appreciated!

Tagged:

Best Answer

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,460 Red Diamond
    Accepted Answer

    As the components don't have a value property set, this will not work. The autosubmit will transfer the data from the UI to the value property. You are trying to access the bound variable (the component itself). This will not work!

    To store the user's input into a component you must set the value property of the component.


    Timo


Answers

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,460 Red Diamond

    User, tell us your exact JDev version, please!

    I'm not sure you can implement it using EL.

    I would use the showRequierd property on both fields using the EL you mentioned to show or hide the '*'. The validation has to be done when you submit the page. There you can validate id one of the fields has a value.

    To make the EL work you need to autosubmit the input to the fields and set their partialTrigger property to the other field.


    Timo


  • ChristianM0147
    ChristianM0147 Member Posts: 18 Red Ribbon
    edited Jul 27, 2021 12:55PM

    My JDev Version is 12.2.1.4.0

    I added the autosubmit attribute and the partialTriggers accordingly but nothing happens. Is the EL right?

    #{empty bean.bindingDate.value}

    These are my Components:

    <af:inputDate label="Datum:" id="id1" autoSubmit="true"
                  labelStyle="font-size:large; text-align:left;"
                  binding="#{testbean.bindingDatum}"
                  columns="10" partialTriggers="sbc4"
                  showRequired="#{empty testbean.bindingUnbekanntesDatum.value}"/>
    <af:selectBooleanCheckbox label="unbekannt:" id="sbc4" autoSubmit="true"
                              binding="#{testbean.bindingUnbekanntesDatum}"
                              partialTriggers="id1"
                              showRequired="#{empty testbean.bindingDatum.value} "/>
    

    I also added the validation to the button that submits all the input fields.

    For the validation: I found out that i should use "ValidatorException" Exception for this. But if i use this Exception no Message is shown in the UI. Can you please tell me how i add the red border around the Date and how i also extend the popup shown in the picture below?

    What i want to achieve is the same look and feel of this:

    Please excuse the Censorship.

  • Timo Hahn
    Timo Hahn Senior Principal Technical Consultant - Oracle ACE Director Member, Moderator Posts: 37,460 Red Diamond
    Accepted Answer

    As the components don't have a value property set, this will not work. The autosubmit will transfer the data from the UI to the value property. You are trying to access the bound variable (the component itself). This will not work!

    To store the user's input into a component you must set the value property of the component.


    Timo