當前位置: 首頁>>代碼示例>>Java>>正文


Java Validator類代碼示例

本文整理匯總了Java中javax.faces.validator.Validator的典型用法代碼示例。如果您正苦於以下問題:Java Validator類的具體用法?Java Validator怎麽用?Java Validator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Validator類屬於javax.faces.validator包,在下文中一共展示了Validator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addOnSubmitConverterValidators

import javax.faces.validator.Validator; //導入依賴的package包/類
public static void addOnSubmitConverterValidators(
  UIComponent         component,
  Converter           converter,
  Iterator<Validator> validators,
  String              clientId,
  boolean             immediate,
  boolean             required,
  String              requiredMessageKey
  ) throws IOException
{
  CoreFormData fData = (CoreFormData)
    RenderingContext.getCurrentInstance().getFormData();

  fData.addOnSubmitConverterValidators(component,
                                       converter,
                                       validators,
                                       clientId,
                                       immediate,
                                       required,
                                       requiredMessageKey);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:22,代碼來源:FormRenderer.java

示例2: doTestIsNotString

import javax.faces.validator.Validator; //導入依賴的package包/類
public void doTestIsNotString(Validator validator)
{
  Mock mock = mock(UIComponent.class);
  UIComponent component = (UIComponent) mock.proxy();
  mock.stubs().method("getId").will(returnValue("test"));
  try
  {
    validator.validate(facesContext, component, new Integer(1));
    // if exception is not thrown - mark it as an failure
    fail("Expected Validator Exception");
  }
  catch (IllegalArgumentException iae)
  {
    // if exception then fine.
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:17,代碼來源:ValidatorTestCase.java

示例3: HtmlNumber

import javax.faces.validator.Validator; //導入依賴的package包/類
public HtmlNumber() {
    super();
    this.setRendererType(RENDERER_TYPE);

    addValidator(new Validator() {
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            try {
                final long longValue = Long.parseLong(value.toString());

                if (getMin() != null && !"".equals(getMin()) && longValue < Integer.valueOf(getMin())) {
                    throw new ValidatorException(new FacesMessage("Number is to small", String.format("%s is to small", value)));
                }

                if (getMax() != null && !"".equals(getMax()) && longValue > Integer.valueOf(getMax())) {
                    throw new ValidatorException(new FacesMessage("Number is to big", String.format("%s is to big", value)));
                }
            } catch (NumberFormatException e) {
                throw new ValidatorException(new FacesMessage("No number", String.format("%s is no number", value)));
            }
        }
    });
}
 
開發者ID:ButterFaces,項目名稱:ButterFaces,代碼行數:24,代碼來源:HtmlNumber.java

示例4: valideFileContent

import javax.faces.validator.Validator; //導入依賴的package包/類
private void valideFileContent(FacesContext context, UIComponent component, String textValue)
{
	  org.owasp.esapi.Validator instance = ESAPI.validator();
ValidationErrorList errors = new ValidationErrorList();
byte[] bytes = null;
try 
{
 bytes = "12345".getBytes(encoding);
	  }
catch (Exception e) 
{
((UIInput) component).setValid(false);
      FacesMessage msg = new FacesMessage("Invalidation File Encoding");
       context.addMessage(component.getClientId(), msg);
 }
}
 
開發者ID:OWASP,項目名稱:EJSF,代碼行數:17,代碼來源:EsapiValidator.java

示例5: isValidateDate

import javax.faces.validator.Validator; //導入依賴的package包/類
private boolean isValidateDate(String textValue) throws ValidatorException
{
	Boolean flag = null;
   	if(textValue != null && !textValue.trim().equals(""))
	{
   		org.owasp.esapi.Validator instance = ESAPI.validator();
   		DateFormat format = SimpleDateFormat.getDateInstance();
   		flag = instance.isValidDate("datetest1", textValue, format, true);
	}
   	else
   	{
   		FacesMessage msg = new FacesMessage("Date validation failed.","Null Input Value.");
		msg.setSeverity(FacesMessage.SEVERITY_ERROR);
		throw new ValidatorException(msg);
   	}
   	
   	return flag;
}
 
開發者ID:OWASP,項目名稱:EJSF,代碼行數:19,代碼來源:EsapiValidator.java

示例6: isValidateCreditCard

import javax.faces.validator.Validator; //導入依賴的package包/類
private boolean isValidateCreditCard(String textValue) throws ValidatorException
{
	Boolean flag = null;
	if(textValue != null && !textValue.trim().equals(""))
	{
		org.owasp.esapi.Validator instance = ESAPI.validator();
		flag = !instance.isValidCreditCard("cctest1", textValue, true);
	}
	else
	{
		FacesMessage msg = new FacesMessage("Credit Card validation failed.","Enter Credit Card Number.");
		msg.setSeverity(FacesMessage.SEVERITY_ERROR);
		throw new ValidatorException(msg);
	}
	
	return flag;
}
 
開發者ID:OWASP,項目名稱:EJSF,代碼行數:18,代碼來源:EsapiValidator.java

示例7: getValidHtmlOutput

import javax.faces.validator.Validator; //導入依賴的package包/類
private String getValidHtmlOutput(UIComponent component,String textValue) throws ValidationException
{
	    org.owasp.esapi.Validator instance = ESAPI.validator();
        ValidationErrorList errors = new ValidationErrorList();

        // new school test case setup
        HTMLValidationRule rule = new HTMLValidationRule("test");
        ESAPI.validator().addRule(rule);

        String filteredTextValue = (String)ESAPI.validator().getRule("test").getValid("test", textValue);
        System.out.println("********** Filtered Value :"+filteredTextValue);
        System.out.println("********** Get Class :"+component.getClass());
        
        
	return filteredTextValue;
}
 
開發者ID:OWASP,項目名稱:EJSF,代碼行數:17,代碼來源:EsapiValidator.java

示例8: _findDateTimeRangeValidator

import javax.faces.validator.Validator; //導入依賴的package包/類
private DateTimeRangeValidator _findDateTimeRangeValidator(
  UIComponent component,
  FacesBean   bean)
{
  Iterator<Validator> validators = getValidators(component, bean);
  while (validators.hasNext())
  {
    Object validator = validators.next();
    if (validator instanceof DateTimeRangeValidator)
      return (DateTimeRangeValidator) validator;
  }

  return null;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:15,代碼來源:SimpleInputDateRenderer.java

示例9: getValidators

import javax.faces.validator.Validator; //導入依賴的package包/類
@SuppressWarnings("unchecked")
protected Iterator<Validator> getValidators(
  UIComponent component,
  FacesBean   bean)
{
  return (Iterator<Validator>)bean.entries(_validatorsKey);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:8,代碼來源:EditableValueRenderer.java

示例10: createValidator

import javax.faces.validator.Validator; //導入依賴的package包/類
/**
 * 
 */
@Override
protected Validator createValidator() throws JspException
{
  Application app = FacesContext.getCurrentInstance().getApplication();
  PasswordValidator validator =
              (PasswordValidator)app.createValidator(PasswordValidator.VALIDATOR_ID);
  return validator;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:12,代碼來源:ValidatePasswordTag.java

示例11: doStartTag

import javax.faces.validator.Validator; //導入依賴的package包/類
@Override
public int doStartTag() throws JspException
{
    UIComponentClassicTagBase componentTag = UIComponentELTag.getParentUIComponentClassicTagBase(pageContext);

    if (componentTag == null)
    {
        throw new JspException("no parent UIComponentTag found");
    }

    if (!componentTag.getCreated())
    {
        return Tag.SKIP_BODY;
    }

    Validator validator = createValidator();

    UIComponent component = componentTag.getComponentInstance();
    if (component == null)
    {
        throw new JspException("parent UIComponentTag has no UIComponent");
    }

    if (!(component instanceof EditableValueHolder))
    {
        throw new JspException("UIComponent is no EditableValueHolder");
    }
    ((EditableValueHolder)component).addValidator(validator);

    return Tag.SKIP_BODY;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:32,代碼來源:TrinidadValidatorELTag.java

示例12: addValidator

import javax.faces.validator.Validator; //導入依賴的package包/類
public void addValidator(Validator validator)
{
  if (validator == null)
    throw new NullPointerException();

  getFacesBean().addEntry(VALIDATORS_KEY, validator);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:8,代碼來源:UIXEditableValueTemplate.java

示例13: doTestNull

import javax.faces.validator.Validator; //導入依賴的package包/類
/**
 * Tests that null returns immediately.
 *
 * @throws ValidatorException  when test fails
 */
protected void doTestNull(
  MockFacesContext context,
  MockUIComponentWrapper wrapper,
  Validator validator
  ) throws ValidatorException
{
  validator.validate(context, wrapper.getUIComponent(), null);

  wrapper.getMock().verify();
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:16,代碼來源:ValidatorTestCase.java

示例14: doTestNullContext

import javax.faces.validator.Validator; //導入依賴的package包/類
/**
 * if contex or component = null then should throw NullPointerException
 */
protected void doTestNullContext(
  MockUIComponentWrapper wrapper,
  Validator validator) throws NullPointerException
{
  try
  {
    validator.validate(null, wrapper.getUIComponent(), "dummy");
    fail("Expected NullpointerException - if context or component is null");
  }
  catch (NullPointerException npe)
  {
    // this is expected
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:18,代碼來源:ValidatorTestCase.java

示例15: doTestNullComponent

import javax.faces.validator.Validator; //導入依賴的package包/類
/**
 * if contex or component = null then should throw NullPointerException
 */
protected void doTestNullComponent(MockFacesContext context,
  Validator validator ) throws NullPointerException
{
  try
  {
    validator.validate(context, null, "dummy");
    fail("Expected NullpointerException - if context or component is null");
  }
  catch (NullPointerException npe)
  {
    // this is expected
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:17,代碼來源:ValidatorTestCase.java


注:本文中的javax.faces.validator.Validator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。