voyent
Validator issue  XML
Forum Index -> Components
Author Message
pbk97030

Joined: 04/Oct/2007 00:00:00
Messages: 17
Offline


Hello guys,

I have an issue with a custom validator. I created a new validator, LoginValidator and defined it in icefaces-config.xml.

I ran it, but it never invoked the method, validate(~, ~, ~).
I was able to check the Validator was actually created, but
the method was not invoked at all.

Please advise me whether I missed anything.

Thanks

Code:
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
 import javax.faces.context.FacesContext;
 import javax.faces.validator.Validator;
 import javax.faces.validator.ValidatorException;
 
 public class LoginValidator implements Validator {
     public LoginValidator() {
     	System.err.println("loginValidator");
     }
     
 	public void validate(FacesContext context, UIComponent component, Object value) {
 		if(null == value || ((String)value).trim().equals("")){
 			FacesMessage msg = new FacesMessage();
 			System.err.println(((UIInput)component).getLocalValue());
 			System.err.println(((UIInput)component).getId());
 			System.err.println(((UIInput)component).getRendererType());
 			msg.setDetail("Invalid username/password");
 			msg.setSummary("Invalid username/password");
 			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
 			throw new ValidatorException(msg);
 		}
     }
 }
 


This is faces-config.xml

Code:
<validator>
         <validator-id>com.nyiso.icefaces.loginValidator</validator-id>
         <validator-class>com.nyiso.icefaces.component.validator.LoginValidator</validator-class>
     </validator>  


This is login.jspx
Code:
 <td align="left">
     <ice:inputText id="username" styleClass="basicInput">
       <f:validator validatorId="com.nyiso.icefaces.loginValidator" />                    	
     </ice:inputText>
 </td>  
pbk97030

Joined: 04/Oct/2007 00:00:00
Messages: 17
Offline


Hi everyone,

If you leave it blank and submit form,
, the validate(~,~,~) method will not be invoked.

In order to prevent this issue, you have to specify the required="true" attribute for <ice:inputText ~~>. So checking blank or null becomes meaningless for this case because the validate method will be skipped.

This is not what I expected, but it is how icefaces work now.
Can it be changed in the future release?

I hoped I would take care of everthing inside a validator including blank check.

If I am wrong, please correct me.

Thanks,

mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


It's not because of ICEfaces, but just how JSF works. Here's the relevant code from javax.faces.component.UIInput :

Code:
protected void validateValue(FacesContext context, Object newValue) {
     // If our value is valid, enforce the required property if present
     if (isValid() && isRequired() && isEmpty(newValue)) {
         ... Makes a FacesMessage
         setValid(false);
     }
 
     // If our value is valid and not empty, call all validators
     if (isValid() && !isEmpty(newValue)) {
         ... // Calls the Validators
     }
 }

[Email]
pbk97030

Joined: 04/Oct/2007 00:00:00
Messages: 17
Offline


Thanks for a reply.

I want to find how to override the method. Is it possible?

If I do find and I will post it.

Thanks,
mark.collette


Joined: 07/Feb/2005 00:00:00
Messages: 1692
Offline


Well, one hack would be for you to add a Converter, which, when given an empty submittedValue, will convert it to some sentinel value that your Validator could check for.
[Email]
 
Forum Index -> Components
Go to:   
Powered by JForum 2.1.7ice © JForum Team