2 Replies Latest reply on Aug 8, 2008 5:26 PM by Stephen Byrne

    Programatically set s:decorate invalid

    Stephen Byrne Newbie

      From the documentation, section 29.1.3.1:


      #{invalid} and #{required} are available inside s:decorate; #{required} evaluates to true if you have set the input component being decorated as required, and #{invalid} evaluates to true if a validation error occurs.


      Is there a way to set invalid to true programatically if I know the component ID of a component inside the s:decorate?


      I have a field A that is rendered if and only if field B is set to X. Field A is required if it is rendered. I cannot set field to required, because if field A is rendered because field B is X and then field A is changed to empty and field B is changed to Y and the form is submitted, field A will fail validation. I cannot write a custom Validator because JSF does not call validators if the value is empty. Thus, I have to do the validation in the Invoke Application phase and add a FacesMessage to the UIComponent for field A. Which is fine, except that when field A is rendered in the Render Response phase, #{invalid} is false so I do not know to render the tooltip in which my FacesMessages for the UIComponent are rendered, so the messages are never displayed.


      It seems that I either need to set invalid progrmatically or modify JSF to call the custom validator on empty fields, perhaps depending on a new attribute on the UIComponent, validateIfEmpty.