I have an "inputSecret" component and I need to enable both HTML native non null validation, as well as JSF validation. Or to switch both of them off based on a parameter.
As a start, I have the xmlns:h="http://xmlns.jcp.org/jsf/html
and xmlns:f="http://xmlns.jcp.org/jsf/core
namespaces imported
This code
<h:inputSecret required="#{passwordRequired}" >
</h:inputSecret>
will enable JSF validation if the passwordRequired parameter is 'true'. And I thought the "required" attrib would also translate into the final HTML to enable native HTML validation, but it does not. So then I used the passThroughAttribute to have the "required" attribute down into the HTML rendered component.
<h:inputSecret required="#{passwordRequired}" >
<f:passThroughAttribute name="required" value="#{passwordRequired}" />
</h:inputSecret>
One problem is that the value of the passThroughAttribute does not really matter, I can set it to "required", "true", "false" or even empty string, the HTML native validation will just occur if I type in the passThroughAttribute tag as described above (again, regardless of value).
This would be fine for the use case I initially had, but there is also a situation in which the use case does not require the user to change the password, so I would like to be able to conditionally add that "required" attrib as a "passThroughAttribute" tag in the JSF code.
Something ala
<h:inputSecret required="#{passwordRequired}" >
<if:condition value="#{passwordRequired}">
<f:passThroughAttribute name="required" value="true" />
</if>
</h:inputSecret>
For an UI component I would use the "render" attribute, but this is not the case. I simply want to be able to switch the inclusion of the "passthroughAttribute" on or off based on my parameter. I know it sounds like JSTL and "c:if" but that doesn't always work so I need something else.
Does anyone know of a method for me to accomplish what I need without some horrible hacks?