1

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)

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

is there any way to remove this attribute with javascript

thank you in advance

Community
  • 1
  • 1
begiPass
  • 2,124
  • 6
  • 36
  • 57

3 Answers3

3

is there any way to remove this attribute with javascript

No. Rightclick page and do View Source in your favourite browser. You'll see that JSF code produces one and all HTML code. The JSF component's converter attribute is nowhere represented in the generated HTML output of <h:inputText>. 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. E.g.

<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;
        }
    }
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you BalusC, it works I tested with this : ` ` it launch the actionListener method only when conversion is done – begiPass May 02 '13 at 13:35
  • but I have one problem : the `p:message` that I put with the inputText (inside datatable) does not show error : ` ` I don't know why – begiPass May 02 '13 at 13:37
  • 1
    You forgot to ajax-udpate the message. This is however a different problem. If you still stucks, press `Ask Question`. – BalusC May 02 '13 at 13:39
-1
$(element).removeAttr("converter");
MMeersseman
  • 2,541
  • 1
  • 13
  • 8
-1

Just set empty value to this attribute.

document.getElementsById("qte").setAttribute("converter","");
Dmitry Volokh
  • 1,630
  • 16
  • 28