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


Java ValidatorException.getFacesMessage方法代码示例

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


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

示例1: getAsObject

import javax.faces.validator.ValidatorException; //导入方法依赖的package包/类
/**
 * Conversion to server representation, so converting days to milliseconds.
 * Prior to the conversion the input value is validated.
 */
@Override
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    try {
        // Checks if mandatory and not empty
        new ParameterValueValidator().validate(context, component, value);
    } catch (ValidatorException e) {
        throw new ConverterException(e.getFacesMessage());
    }

    // Validation passed; so if the value is empty it's not mandatory
    if (value == null || value.trim().length() == 0) {
        return null;
    } else {
        Long durationInMs = DurationValidation.convertDurationToMs(context,
                value);
        if (durationInMs != null) {
            return durationInMs.toString();
        } else {
            throw new ConverterException(
                    ParameterValueValidator.getFacesMessage(component,
                            context));
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:DurationConverter.java

示例2: testInvalidDaysOfWeek

import javax.faces.validator.ValidatorException; //导入方法依赖的package包/类
/**
   * Tests that invalid day, like Fri or Sun cause a ValidationException.
   */
  public void testInvalidDaysOfWeek()
  {
    DateRestrictionValidator validator = new DateRestrictionValidator();
    validator.setInvalidDaysOfWeek(new String[] {"mon", "Sun"});

    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    setMockLabelForComponent(wrapper);
    
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dateToValidate = null;
    
    try
    {
      dateToValidate = sdf.parse("30.10.2006");
    }
    catch (ParseException e1)
    {
    }

    setMockCreateConverter(application);
    try
    {
      setFacesContext(facesContext);
      validator.validate(facesContext, component, dateToValidate);
      fail("ValidatorException not thrown");
    }
    catch (ValidatorException e)
    {
      // pass
//      String msg = e.getFacesMessage().getDetail();
//      assertEquals(msg, "max set");
      
      FacesMessage msg = e.getFacesMessage();
      assertNotNull(msg);
      
    }
    finally
    {
      setFacesContext(null);
    }
  }
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:47,代码来源:DateRestrictionValidatorTest.java

示例3: testInvalidMonth

import javax.faces.validator.ValidatorException; //导入方法依赖的package包/类
/**
   * Tests that invalid day, like Fri or Sun cause a ValidationException.
   */
  public void testInvalidMonth()
  {
    
    DateRestrictionValidator validator = new DateRestrictionValidator();
    validator.setInvalidMonths(new String[] {"Jan", "Oct"});

    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    setMockLabelForComponent(wrapper);
    
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dateToValidate = null;
    
    try
    {
      dateToValidate = sdf.parse("30.10.2006");
    }
    catch (ParseException e1)
    {
    }

    setMockCreateConverter(application);
    try
    {
      setFacesContext(facesContext);
      validator.validate(facesContext, component, dateToValidate);
      fail("ValidatorException not thrown");
    }
    catch (ValidatorException e)
    {
      // pass
//      String msg = e.getFacesMessage().getDetail();
//      assertEquals(msg, "max set");
      
      FacesMessage msg = e.getFacesMessage();
      assertNotNull(msg);
      
    }
    finally
    {
      setFacesContext(null);
    }
  }
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:48,代码来源:DateRestrictionValidatorTest.java

示例4: testInvalidDays

import javax.faces.validator.ValidatorException; //导入方法依赖的package包/类
/**
   * Tests that invalid day, like Fri or Sun cause a ValidationException.
   */
  public void testInvalidDays()
  {
    
    DateRestrictionValidator validator = new DateRestrictionValidator();
    TestDateListProvider tdlp = new TestDateListProvider();
    validator.setInvalidDays(tdlp);

    Mock mock = buildMockUIComponent();
    UIComponent component = (UIComponent) mock.proxy();
    MockUIComponentWrapper wrapper = new MockUIComponentWrapper(mock, component);
    setMockLabelForComponent(wrapper);
    
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dateToValidate = null;
    
    try
    {
      dateToValidate = sdf.parse("15.05.2007");
    }
    catch (ParseException e1)
    {
    }

    setMockCreateConverter(application);
    try
    {
      setFacesContext(facesContext);
      validator.validate(facesContext, component, dateToValidate);
      fail("ValidatorException not thrown");
    }
    catch (ValidatorException e)
    {
      // pass
//      String msg = e.getFacesMessage().getDetail();
//      assertEquals(msg, "max set");
      
      FacesMessage msg = e.getFacesMessage();
      assertNotNull(msg);
      
    }
    finally
    {
      setFacesContext(null);
    }
  }
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:49,代码来源:DateRestrictionValidatorTest.java


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