How could I always convert the property username
to lower case?
This does not work:
<h:inputText value="#{userService.user.username.toLowerCase()}" />
as target gets "unreachable" by this. How could I else do this?
The toLowerCase() method returns the value of the string converted to lower case. toLowerCase() does not affect the value of the string str itself.
The toLowerCase() method converts a string to lower case letters. Note: The toUpperCase() method converts a string to upper case letters.
The toLowerCase() method converts a string to lowercase letters. The toLowerCase() method does not change the original string.
The toLowerCase() is an inbuilt function in TypeScript which is used to convert the characters within a string to lowercase.
<h:inputText value="#{userService.user.username.toLowerCase()}" />
You can't perform a "set" operation on the given EL expression, while this is mandatory in order to update the model value with the submitted value. The toLowerCase()
method expression doesn't have a corresponding setter method.
Technically, you should be creating a Converter
for the job. Here's a kickoff example:
@FacesConverter("toLowerCaseConverter")
public class ToLowerCaseConverter implements Converter {
@Override
public String getAsString(FacesContext context, UIComponent component, Object modelValue) {
if (!(modelValue instanceof String)) {
return null; // Or throw ConverterException.
}
return ((String) modelValue).toLowerCase();
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
if (submittedValue == null) {
return null;
}
return submittedValue.toLowerCase();
}
}
Use it as follows:
<h:inputText value="#{userService.user.username}" converter="toLowerCaseConverter" />
You should preferably not clutter the model with conversion strategies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With