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?
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?
<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.
You can use jstl function for this
include: <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
and use < h:inputText value="${fn:toLowerCase(string)}"/>
Or you can make username in lowercase in java by .toLowerCase().
This way should work. As soon as you set the name, the name is lowecased.
String name;
public void setName(String name){
this.name = name.toLowerCase();
}