5

我正在编写一个自定义验证器来检查用户输入的 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

提前谢谢你

4

3 回答 3

10

org.apache.commons.validator.UrlValidator包中的 UrlValidator已弃用,请使用此Routines包中的 UrlValidator:

于 2013-01-11T09:22:21.063 回答
1

The UrlValidator that you are using is deprecated an will be removed in future releases.

You should replace it by the UrlValidator in the routines package. The routines package can be found in the Apache Commons Validator component.

于 2013-01-11T09:25:40.907 回答
1

根据JavaDoc:

在routines 包中使用新的UrlValidator。此类将在未来的版本中删除。

于 2013-01-11T09:20:59.893 回答