我正在编写一个自定义验证器来检查用户输入的 url:
package tn.talan.testFramework.validators;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
import org.apache.commons.validator.UrlValidator;
public class URLCustomValidator implements Validator{
public void validate(FacesContext context, UIComponent component,Object value) throws ValidatorException {
String enteredURL = (String) value;
String[] schemes = {"http","https"};
System.out.println(enteredURL);
FacesMessage message = null ;
String messageStr = null ;
UrlValidator urlValidator = new UrlValidator(schemes);
if (!urlValidator.isValid(enteredURL)) {
System.out.println("url is invalid valid");
message = new FacesMessage();
messageStr = (String)component.getAttributes().get("message");
if (messageStr == null) {
messageStr = "Inavalid URL";
}
message.setDetail(messageStr);
message.setSummary(messageStr);
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
}
}
}
我收到此警告,我想解决它:
The type UrlValidator is deprecated
提前谢谢你