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