I am new to JSF and going through one JSF application.
I want to validate one Password field for Blank string.
I know instead of doing it in Javascript, I am calling a function for validation.
My need is, if value of the password field is blank then it is validated from validator function till now it is going correctly but after validation when it come =s to UI bav=ck at that time password field should be empty.
If password field is empty(contains spaces only) then i want it to set it as blank or else keep data as it is.
My try till now, JSF view page singin.xhtml
<h:outputText styleClass="outputBox" style="margin: 3px;"
value="Password" />
<h:inputSecret id="password" required="true"
requiredMessage="Please enter your password"
value="#{userActionManager.dto.password}"
validator="#{userActionManager.validateSamePassword}">
<a4j:ajax event="change" execute="@this" bypassUpdates="true" />
</h:inputSecret>
Validator method.
public void validateSamePassword(FacesContext fc, UIComponent component, Object obj) {
System.out.println("UserActionManager.validateSamePassword()");
String confirmPassword = (String)obj;
System.out.println("Password is :" + confirmPassword);
if(confirmPassword!=null && confirmPassword.trim().equals("")) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Password cannot be blank", " detail Passwords do not match!");
// System.out.println(component.getFamily());
// String field1Id = (String) component.getAttributes().get("password");
// Find the actual JSF component for the client ID.
// UIInput textInput = (UIInput) fc.getViewRoot().findComponent("password");
// textInput.setValue("");
dto.setPassword(null);
throw new ValidatorException(message);
}else{
dto.setPassword(confirmPassword);
}
}
I tried option dto.setPassword(null); but when it returns to view, blank spaces in password field is still there and i have to manually remove.
what I am missing?