can I validate two interdependent fields in with one validator?
<h:form>
<h:inputText value="#{logRegBean.person.name}" >
<f:validator validatorId="loginCorrectValidator" />
</h:inputText>
<h:inputSecret value="#{logRegBean.person.password}" />
<h:commandButton action="#{logRegBean.login}" />
</h:form>
I want to search for the user in the DB and if there is the user, I’ll test if the passwords(in db and inputted) match. But how can I access even the password field in one validator? I tried to evaluate the value int the other field via createValueExpression(), but it looks like I can’t access the value in that time since I always get empty strings.
Best what you can do is to grab the other
UIInputcomponent byUIViewRoot#findComponent()inside thevalidate()method and then determine the submitted value by eitherUIInput#getSubmittedValue()(when it occurs after the currently validated component in the component tree) orUIInput#getValue()(when it occurs before the current component and thus is already validated).E.g.
See also: