problem in validator method

Hi to all, i have this jsf code:

<h:outputText value="#{bundle.oldPassword}:" />

<h:inputSecret id="oldPassword" value="#{userManager.oldPassword}" required="true"></h:inputSecret>

<t:message id="oldPasswordError" for="oldPassword" styleClass="error"/>

<h:outputText value="#{bundle.newPassword}:" />

<h:inputSecret id="newPassword" validator="#{userManager.validateChangePassword}" value="#{userManager.newPassword}" required="true"></h:inputSecret>

<t:message id="newPasswordError" for="newPassword" styleClass="error"/>

<h:outputText value="#{bundle.retypePassword}:" />

<h:inputSecret id="retypePassword" value="#{userManager.retypePassword}" required="true"></h:inputSecret>

<t:message id="retypePasswordError" for="retypePassword" styleClass="error"/>

The field "newPassword" has the validator method "validateChangePassword".

The validator method is (is a test):

public void validateChangePassword(FacesContext fc, UIComponent ui, Object o){

UIInput old = (UIInput)fc.getViewRoot().findComponent("oldPassword");

UIInput pass = (UIInput)fc.getViewRoot().findComponent("newPassword");

UIInput retp = (UIInput)fc.getViewRoot().findComponent("retypePassword");

System.out.println(" "+old.getValue());

System.out.println(" "+pass.getValue());

System.out.println(" "+retp.getValue());

FacesMessage facesMessage = new FacesMessage("Error password");

throw new ValidatorException(facesMessage);

}

I must know the values of all three fields in jsf page, but, with the method above, i get only the value of one of the fields, the others return null.

How can i do to getting all three values?

Thanks!

[1861 byte] By [paolo77a] at [2007-10-2 5:45:46]
# 1

The local value of an input component is set after conversion and validation.

You don't need to find newPassword value because you already have it as the

third parameter of the method, i.e. Object o.

You can't get a local value of retypePassword because the value hasn't been

converted nor validated. Instead, you can get the submitted value; getSubmittedValue().

But wait! You may understand that the ways to get these three values

depend on the order of the components. Very ugly.

This means that JSF's validator is not designed for cross values validation.

It is designed for single value validation, I think.

I recommend you that the validation you want should be done in the action method.

yuki.yoshidaa at 2007-7-16 1:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Ok thanks, now i do the validation in the method of the form action.Bye
paolo77a at 2007-7-16 1:55:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...