本文整理汇总了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));
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}