如何禁用默认的JSF验证和一个输入字段的转换 [英] How to disable default JSF validation and conversion of one input field

查看:108
本文介绍了如何禁用默认的JSF验证和一个输入字段的转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想禁用默认的JSF验证和一个输入字段inputtext的转换,以便能够使用jQuery对其进行验证.

I want to disable the default JSF validation and conversion of one input field inputtext in order to be able to validate it using jQuery.

<p:column headerText="Quantité"> 
    <p:inputText widgetVar="input_qte" styleClass="my_qte" value="#{arti.qte}">
        <f:validateBean disabled="true"/>
    </p:inputText> \
    <h:outputText styleClass="my_qtemax" value="#{arti.qtemax}" />
    <div class="my_validator" style="display : none;">Valeur Invalide</div>
</p:column>

#{arti.qte}绑定到Double属性.

我该如何实现?

推荐答案

据我所提供的信息,目前尚未对该组件进行验证.当您绑定非String类型作为输入组件的值时,也许您专门指的是隐式转换?不,您不能禁用此功能.您只能通过提供一个自定义转换器来解决该问题,该转换器不会引发异常,而只会在失败时返回null.

There's already no validation on that component, as far as I see in the information provided so far. Perhaps you specifically meant the implicit conversion when you bind a non-String type as input component's value? No, you can't disable this. You can only workaround it by supplying a custom converter which doesn't throw an exception, but just returns null on failure.

例如通过仅扩展标准JSF DoubleConverter 并完全抑制getAsObject()上的ConverterException:

E.g. by just extending the standard JSF DoubleConverter and totally suppressing the ConverterException on getAsObject():

@FacesConverter("lenientDoubleConverter")
public class LenientDoubleConverter extends DoubleConverter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            return super.getAsObject(context, component, value);
        } catch (ConverterException ignore) {
            return null;
        }
    }

}

然后将哪个用作:

<p:inputText ... converter="lenientDoubleConverter" />


无关与具体问题无关,请注意,客户端验证/转换绝对不可靠.由于JavaScript在客户端完全运行,因此最终用户可以完全控制正在执行的代码. IE.最终用户可以轻松地禁用,绕过,欺骗等等.另请参见 JSF2验证是客户端还是服务器端?


Unrelated to the concrete problem, please note that client side validation/conversion is absolutely not reliable. As JavaScript runs fully at the client side, the enduser has full control over the code being executed. I.e. the enduser can easily disable, bypass, spoof it, etc. See also JSF2 Validation Clientside or Serverside?

这篇关于如何禁用默认的JSF验证和一个输入字段的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆