How to check the value of two components are the same or not? JSF

How do we compare id in Asp.Net, what do we have in JSF to check if two field values ​​are the same or not? I want to confirm the password and confirm the Password field.

+2


source to share


1 answer


No, such a validator does not exist in the main JSF implementation. You basically need to run a validator on the last component of the group and grab another component that you want to validate as well using UIViewRoot#findComponent()

, For example.

public void validate(FacesContext context, UIComponent component, Object value) {
    UIComponent otherComponent = context.getViewRoot().findComponent("otherClientId");
    Object otherValue = ((UIInput) otherComponent).getValue();
    // ...
}

      

Also see this article for more information and specific examples.

On the other hand, if you are already on JSF2, you can also use ajaxical validation:



<h:form>
    <f:event type="postValidate" listener="#{bean.validate}" />
     ...
</h:form>

      

.. where the #{bean.validate}

method looks like this:

public void validate(ComponentSystemEvent e) {
    UIComponent form = e.getComponent();
    UIComponent oneComponent = form.findComponent("oneClientId");
    UIComponent otherComponent = form.findComponent("otherClientId");
    // ...
} 

      

Also see this article for more detailed JSF2 validation examples.

+6


source







All Articles