我有这个输入:
<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/