javascript - 更改 h :inputText attribute with javascript jsf2

标签 javascript jsf-2 input converters

我有这个输入:

    <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>

如上面的代码所示(converter="lenientDoubleConverter") I use this converter (to disable the implicit conversion of jsf2)

但是当用户单击一个按钮后我想启用它,那么我应该在请求发送到服务器之前使用 JavaScript 删除此转换器

有没有办法用javascript删除这个属性

提前谢谢

最佳答案

is there any way to remove this attribute with javascript

没有。右键单击页面并在您喜欢的浏览器中执行查看源代码。您将看到 JSF 代码生成一份且全部 HTML 代码。 JSF 组件的 converter <h:inputText> 生成的 HTML 输出中没有表示属性。更重要的是,转换器根本不在客户端运行。它只是一个服务器端声明,转换器在服务器端运行。

最好的办法是让按钮添加某个请求参数,指示转换器不宽松。例如

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

@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;
        }
    }
}

关于javascript - 更改 h :inputText attribute with javascript jsf2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16337630/

相关文章:

javascript - 使用 jQuery 获取 URL 参数并将它们显示在 HTML 输入文本字段中

jsf-2 - 是否有可能有一个 richfaces :pickList with a search box?

servlets - 确切地说,@Inject 注释何时在 Servlet 中启动 SessionScoped bean 的注入(inject)?

css - 如何在 richfaces 之后加载自定义 css?

html - &lt;input/> 上的 Opera 12.14 border-radius 不工作

javascript - 使用 javascript 在元素中创建元素

javascript - 使用 Bootstrap3 更改滚动 Jquery 上导航栏的高度

javascript - Jquery clone() 未按预期工作

android - 如何在我的 Android 设备上创建新的虚拟鼠标设备?

Perl,如何在循环外从标准输入读取?