3

I want to disable the default JSF validation and conversion of one input field inputtext in order to be able to validate it using jQuery.

<p:column headerText="Quantité"> 
    <p:inputText widgetVar="input_qte" styleClass="my_qte" value="#{arti.qte}">
        <f:validateBean disabled="true"/>
    </p:inputText> \
    <h:outputText styleClass="my_qtemax" value="#{arti.qtemax}" />
    <div class="my_validator" style="display : none;">Valeur Invalide</div>
</p:column>

The #{arti.qte} is bound to a Double property.

How can I achieve this?

Charles
  • 50,943
  • 13
  • 104
  • 142
begiPass
  • 2,124
  • 6
  • 36
  • 57

1 Answers1

4

There's already no validation on that component, as far as I see in the information provided so far. Perhaps you specifically meant the implicit conversion when you bind a non-String type as input component's value? No, you can't disable this. You can only workaround it by supplying a custom converter which doesn't throw an exception, but just returns null on failure.

E.g. by just extending the standard JSF DoubleConverter and totally suppressing the ConverterException on getAsObject():

@FacesConverter("lenientDoubleConverter")
public class LenientDoubleConverter extends DoubleConverter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        try {
            return super.getAsObject(context, component, value);
        } catch (ConverterException ignore) {
            return null;
        }
    }

}

Which is then used as:

<p:inputText ... converter="lenientDoubleConverter" />

Unrelated to the concrete problem, please note that client side validation/conversion is absolutely not reliable. As JavaScript runs fully at the client side, the enduser has full control over the code being executed. I.e. the enduser can easily disable, bypass, spoof it, etc. See also JSF2 Validation Clientside or Serverside?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Yes you are right, only for this time I used the client side validation because I didn't find the solution of my problem with default jsf2 – begiPass Apr 25 '13 at 02:20