Reputation: 12876
I followed the example here: Why does <h:inputText required="true"> allow blank spaces? to create a "Global" converter to trim all input fields. However, the converter is not being invoked when input fields are submitted.
@FacesConverter(forClass=String.class)
...
<p:inputText value="#{controller.inputValue}"/>
but when I change to:
@FacesConverter("StringTrimmer")
...
<p:inputText value="#{controller.inputValue}" converter="StringTrimmer"/>
it works.
Using Mojarra 2.1.7 and PrimeFaces 3.2
Upvotes: 1
Views: 6161
Reputation: 1451
If you checked that the bound variable is of type String and the converter still doesn't get called, you may also check the following:
If the input component is encapsulated inside a composite component, you may have this issue. In that case, converters would not be called correctly, resulting in your custom method to be never reached. Calling the converter explicitly on the input component solves this.
If you add both value="someName"
and forClass="someClass"
to the @FacesConverter
annotation, the forClass attribute will be ignored. This has been reported here.
Upvotes: 1
Reputation: 1109532
A converter with a forClass
will only be invoked whenever the type of the property is an instance of the specified class. In your particular case, that can only mean that the #{controller.inputValue}
is not of type String
.
Upvotes: 3
Reputation: 12876
This didnt work because the inputValue was not actually of type String. Once changed to type String-- it worked.
Upvotes: 0