简体   繁体   English

使用javascript jsf2更改h:inputText属性

[英]change h:inputText attribute with javascript jsf2

I have this input : 我有这个输入:

    <p:column headerText="Quantité">
        <h:inputText styleClass="maqte" id="qte"
            onkeyup="validerInput($(this),$(this).parent().prev().find('.monpu'));"
            value="#{car.qte}" converter="lenientDoubleConverter" >

        </h:inputText>
    </p:column>

as shown in code above ( converter="lenientDoubleConverter" ) I use this converter (to disable the implicit conversion of jsf2) 如上面的代码所示( converter="lenientDoubleConverter" ), 我使用了此转换器(以禁用jsf2的隐式转换)

but after when the user click on one button I want to enable it, then I should remove this converter with javascript before the request is sent to ther server 但是当用户单击一个按钮后,我要启用它,然后在将请求发送到服务器之前,我应该使用javascript删除此转换器

is there any way to remove this attribute with javascript 有没有办法用javascript删除此属性

thank you in advance 先感谢您

is there any way to remove this attribute with javascript 有没有办法用javascript删除此属性

No. Rightclick page and do View Source in your favourite browser. 否。右键单击页面,然后在您喜欢的浏览器中执行“ 查看源代码” You'll see that JSF code produces one and all HTML code. 您将看到JSF代码生成了一个HTML代码。 The JSF component's converter attribute is nowhere represented in the generated HTML output of <h:inputText> . 在生成的<h:inputText> HTML输出中,没有显示JSF组件的converter属性。 Even more, the converter doesn't run in client side at all. 甚至,转换器根本不在客户端运行。 It's merely a server-side declaration and the converter runs in server side. 它只是服务器端的声明,转换器在服务器端运行。

Your best bet is to let the button add a certain request parameter which instructs the converter to be non-lenient. 最好的选择是让按钮添加某个请求参数,该参数指示转换器不宽容。 Eg 例如

<p:commandButton ...>
    <f:param name="disableLenientDoubleConverter" value="true" />
</p:commandButton>

with

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    try {
        return super.getAsObject(context, component, value);
    } catch (ConverterException e) {
        if ("true".equals(context.getExternalContext().getRequestParameterMap().get("disableLenientDoubleConverter"))) {
            throw e;
        } else {
            return null;
        }
    }
}
$(element).removeAttr("converter");

只需为此属性设置空值。

document.getElementsById("qte").setAttribute("converter","");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM