Skip required validation and invoke the application

前端 未结 1 773
别那么骄傲
别那么骄傲 2020-11-30 14:40

I asked my question here but I think it lacks some obvious information. Hence I\'m posting my question again.

I have a JSF form which has some required validation o

相关标签:
1条回答
  • 2020-11-30 15:14

    Just put that condition straight in the required attribute.

    <h:inputText ... required="#{someCondition}" />
    

    It namely just accepts any EL expression like as many other attributes. Many starters think that you can only hardcode a "true" or "false" string in it. This is untrue.

    For example, when you want to let it evaluate true only when the save button is actually pressed:

    <h:inputText ... required="#{not empty param[save.clientId]}" />
    ...
    <h:commandButton value="Cancel" ... />
    <h:commandButton binding="#{save}" value="Save" ... />
    

    (note: code is complete as-is, you do not need to bind it to a bean property)

    This way the required attribute only evaluates true when the save button is pressed and it evaluates false for any other button or ajax event listener.

    0 讨论(0)
提交回复
热议问题