我正在编写一个自定义验证器,以检查用户输入的网址:
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
预先谢谢你
最佳答案
已弃用org.apache.commons.validator.UrlValidator软件包中的UrlValidator,请使用此Routines软件包中的UrlValidator: