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

3 Answers 3

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;
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

thank you BalusC, it works I tested with this : <p:commandButton value="valider" process="@this lesarticles" actionListener="#{commandeMB.listener}" > <f:param name="disableLenientDoubleConverter" value="true" /> </p:commandButton> it launch the actionListener method only when conversion is done
but I have one problem : the p:message that I put with the inputText (inside datatable) does not show error : <p:column headerText="Quantité"> <h:inputText styleClass="maqte" id="qte" onkeyup="validerInput($(this),$(this).parent().prev().find('.monpu'));" value="#{car.qte}" converter="lenientDoubleConverter" required="true" converterMessage="double" > </h:inputText> <p:message for="qte" /> </p:column> I don't know why
You forgot to ajax-udpate the message. This is however a different problem. If you still stucks, press Ask Question.
-1
$(element).removeAttr("converter");

2 Comments

This is jQuery, not JavaScript:)
jQuery is JavaScript actually ;). But I get what your point is.
-1

Just set empty value to this attribute.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.