Validating empty fields with inline validation method and validator class

前端 未结 1 727
没有蜡笔的小新
没有蜡笔的小新 2020-12-18 08:58

I have the following input field:


If the field is empty it w

相关标签:
1条回答
  • 2020-12-18 09:51

    You've hit an oversight in JSF. The validator is wrapped in a MethodExpressionValidator which according to the source of its validate() method indeed skips validation when the value is null.

    if (value != null) {
        try {
            ELContext elContext = context.getELContext();
            methodExpression.invoke(elContext, new Object[]{context, component, value});
            ...
    

    This is not considering the new JSF 2.0 javax.faces.VALIDATE_EMPTY_FIELDS context parameter which defaults to true. It should actually be doing the same as UIInput#validate().

    if (!isEmpty(newValue) || validateEmptyFields(context)) {
        try {
            ELContext elContext = context.getELContext();
            methodExpression.invoke(elContext, new Object[]{context, component, value});
            ...
    

    This has already been reported as Mojarra issue 1508. I've voted it and added a new comment to wake them up.

    0 讨论(0)
提交回复
热议问题