当前位置: 首页>>代码示例>>Java>>正文


Java ValidatorException类代码示例

本文整理汇总了Java中javax.faces.validator.ValidatorException的典型用法代码示例。如果您正苦于以下问题:Java ValidatorException类的具体用法?Java ValidatorException怎么用?Java ValidatorException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ValidatorException类属于javax.faces.validator包,在下文中一共展示了ValidatorException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
/**
 * Validates that the given value is an URL
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to validate
 * @throws ValidatorException
 *             if validation fails
 */
public void validate(FacesContext facesContext, UIComponent component,
        Object value) throws ValidatorException {
    if (value == null) {
        return;
    }
    String str = value.toString();
    if (str.length() == 0) {
        return;
    }

    if (ADMValidator.isUrl(str)) {
        return;
    }
    Object[] args = null;
    String label = JSFUtils.getLabel(component);
    if (label != null) {
        args = new Object[] { label };
    }
    ValidationException e = new ValidationException(
            ValidationException.ReasonEnum.URL, label, null);
    String text = JSFUtils.getText(e.getMessageKey(), args, facesContext);
    throw new ValidatorException(new FacesMessage(
            FacesMessage.SEVERITY_ERROR, text, null));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:37,代码来源:UrlValidator.java

示例2: validate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
/**
 * Validates that the given value doesn't contain a '{', '}' or "/*".
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to validate
 * @throws ValidatorException
 *             if validation fails
 */
public void validate(FacesContext facesContext, UIComponent component,
        Object value) throws ValidatorException {
    if (value == null) {
        return;
    }
    String str = value.toString();
    if (str.indexOf('{') < 0 && str.indexOf('}') < 0
            && str.indexOf("/*") < 0) {
        return;
    }
    Object[] args = null;
    String label = JSFUtils.getLabel(component);
    // if (label != null) {
    // args = new Object[] { label, str };
    // } else {
    // args = new Object[] { "", str };
    // }
    ValidationException e = new ValidationException(
            ValidationException.ReasonEnum.CSS_VALUE, label, null);
    String text = JSFUtils.getText(e.getMessageKey(), args, facesContext);
    throw new ValidatorException(new FacesMessage(
            FacesMessage.SEVERITY_ERROR, text, null));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:36,代码来源:CssValueValidator.java

示例3: validate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
private static void validate(FacesContext context, UIComponent uiComponent,
        String value) throws ValidatorException {
    Long minValue = getMinValue(uiComponent);
    Long maxValue = getMaxValue(uiComponent);
    long parsedLong = parse(context, value, minValue, maxValue);
    if (!isInRange(parsedLong, minValue, maxValue)) {
        minValue = (minValue != null ? minValue : Long
                .valueOf(Long.MIN_VALUE));
        maxValue = (maxValue != null ? maxValue : Long
                .valueOf(Long.MAX_VALUE));
        String message = JSFUtils.getText(
                BaseBean.ERROR_LONG_VALUE_OUT_OF_RANGE,
                new String[] { String.valueOf(minValue),
                        String.valueOf(maxValue) }, context);
        throw getException(message);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:LongValidator.java

示例4: parse

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
/**
 * Parses the specified string into a long integer.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to parse
 * @throws ValidatorException
 *             if the specified string could not be parsed into a valid long
 *             integer.
 */
public static long parse(FacesContext context, UIComponent uiComponent,
        String value) throws ValidatorException {
    if (!GenericValidator.isLong(value)) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.LONG, label, null);
        String message = JSFUtils.getText(e.getMessageKey(), args, context);
        throw getException(message);
    }
    return Long.parseLong(value);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:29,代码来源:LongValidator.java

示例5: testWrongType

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
public void testWrongType()
{
  // since the pattern has not been set it will be null
  // let us push some arbitary value
  Mock mock = mock(UIComponent.class); 
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LongRangeValidator validator = new LongRangeValidator();
    validator.setMaximum(2);
    validator.validate(facesContext, component, "thisShouldFail");
    // test fails if it is here

    fail("Expected Null pointer exception");
  }
  catch (ValidatorException ve)
  {
    // suppress it - this is as expected
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LongRangeValidatorTest.java

示例6: validate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
@Override
public void validate(FacesContext context, UIComponent uiComponent,
        Object input) throws ValidatorException {
    String value = null;
    if (input != null) {
        value = input.toString();
    }
    if (value == null || value.length() == 0) {
        return;
    }
    if (!getApplicationBean().getActiveLocales().contains(value)) {
        ValidatorException e = getException(JSFUtils.getText(
                BaseBean.ERROR_LOCALE_INVALID, new String[] { new Locale(
                        value).getDisplayLanguage(ui.getViewLocale()) },
                context));
        throw e;
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:SupportedLanguageValidator.java

示例7: validate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
@Override
public void validate(
  FacesContext context,
  UIComponent  component,
  Object       value) throws ValidatorException
{
  if (value == null)
    return;
  
  if (!(value instanceof Date))
  {
    GenericConverterFactory fac = GenericConverterFactory.getCurrentInstance();
    value = fac.convert(value, Date.class);
  }
  super.validate(context, component, value);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:DateTimeRangeValidator.java

示例8: testTooLargeLength

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
public void testTooLargeLength()
{
  // since the pattern has not been set it will be null
  // let us push some arbitary value
  Mock mock = mock(UIComponent.class); 
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LengthValidator validator = new LengthValidator();
    validator.setMaximum(2);
    validator.validate(facesContext, component, "someValue");
    // test fails if it is here

    fail("Expected Null pointer exception");
  }
  catch (ValidatorException ve)
  {
    // suppress it - this is as expected
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LengthValidatorTest.java

示例9: testExactFailure

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
public void testExactFailure()
{
  // some very basic sanity test
  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    DoubleRangeValidator validator = new DoubleRangeValidator();
    double value = 20d;
    validator.setMinimum(2);
    validator.setMaximum(2);
    validator.validate(facesContext, component, value);
    fail("Expected ValidatorException for exact");
  }
  catch (ValidatorException ve)
  {
    // if exception then fine.
  }

  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:DoubleRangeValidatorTest.java

示例10: testWithinDateRange

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
/**
 * Tests that dates within the date range are valid.
 *
 * @throws ValidatorException  when test fails
 */
public void testWithinDateRange() throws ValidatorException
{
  long millis = System.currentTimeMillis();
  DateTimeRangeValidator validator = new DateTimeRangeValidator();
  validator.setMinimum(new Date(millis));
  validator.setMaximum(new Date(millis + 2));

  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();

  try
  {
    setFacesContext(facesContext);
    validator.validate(facesContext, component, new Date(millis + 1));
  }
  finally
  {
    setFacesContext(null);
  }

  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:28,代码来源:DateTimeRangeValidatorTest.java

示例11: testTooLarge

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
public void testTooLarge()
{
  // since the pattern has not been set it will be null
  // let us push some arbitary value
  Mock mock = mock(UIComponent.class); 
  UIComponent component = (UIComponent) mock.proxy();
  MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
  setMockLabelForComponent(wrapper);

  try
  {
    LongRangeValidator validator = new LongRangeValidator();
    validator.setMaximum(100);
    validator.validate(facesContext, component, 1000);
    // test fails if it is here

    fail("Expected Null pointer exception");
  }
  catch (ValidatorException ve)
  {
    // suppress it - this is as expected
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:25,代码来源:LongRangeValidatorTest.java

示例12: testBeforeMaximumDate

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
/**
 * Tests that dates before the maximum date are valid.
 *
 * @throws ValidatorException  when test fails
 */
public void testBeforeMaximumDate() throws ValidatorException
{
  long millis = System.currentTimeMillis();
  DateTimeRangeValidator validator = new DateTimeRangeValidator();
  validator.setMaximum(new Date(millis));

  Mock mock = buildMockUIComponent();
  UIComponent component = (UIComponent) mock.proxy();

  try
  {
    setFacesContext(facesContext);
    validator.validate(facesContext, component, new Date(millis - 1));
  }
  finally
  {
    setFacesContext(null);
  }
  mock.verify();
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:DateTimeRangeValidatorTest.java

示例13: testValidate_String_Mandatory_TypeBoolean_Null

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
@Test(expected = ValidatorException.class)
public void testValidate_String_Mandatory_TypeBoolean_Null() {
    // given
    UIComponentStub stub = getComponent(ConfigurationKey.TYPE_BOOLEAN,
            true, null, null);

    // when
    validator.validate(context, stub, null);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:ConfigurationSettingsValidatorTest.java

示例14: testValidate_String_Mandatory_TypeLong_Null

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
@Test(expected = ValidatorException.class)
public void testValidate_String_Mandatory_TypeLong_Null() {
    // given
    UIComponentStub stub = getComponent(ConfigurationKey.TYPE_LONG, true,
            null, null);

    // when
    validator.validate(context, stub, null);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:ConfigurationSettingsValidatorTest.java

示例15: testValidateNullParameters

import javax.faces.validator.ValidatorException; //导入依赖的package包/类
@Test(expected = ValidatorException.class)
public void testValidateNullParameters() throws Exception {
    validator.validate(fcStub, fromDateStub, null);

    validator.validate(fcStub, toDateStub, null);
    DateFromToValidator spy = spy(validator);
    doNothing().when(spy).handleError(Matchers.any(FacesContext.class),
            Matchers.anyString(), Matchers.anyString());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:10,代码来源:DateFromToValidatorTest.java


注:本文中的javax.faces.validator.ValidatorException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。