I have a custom converter which is this :
@ManagedBean
@RequestScoped
public class MeasureConverter implements Converter {
@EJB
private EaoMeasure eaoMeasure;
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (!(value instanceof Measure) || ((Measure) value).getId() == null) {
return null;
}
return String.valueOf(((Measure) value).getId());
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value == null || !value.matches("\\d+")) {
return null;
}
Measure measure = eaoMeasure.find(Integer.valueOf(value));
if (measure == null) {
throw new ConverterException(new FacesMessage("Unknown Measure ID: " + value));
}
return measure;
}
But I would like to validate this as I'm doing with the other fields, just like this for example :
<h:outputLabel for="name" value="Name:" />
<h:inputText id="name" value="#{bean.name}">
<f:ajax event="blur" listener="#{validator.name}" render="m_name" />
</h:inputText>
<rich:message id="m_name" for="name" ajaxRendered="false" />
So when the blur
event occurs an icon appears indicating if the selection in correct or not (the code above do this what I'm talking )
But I want to apply this kind of validation in this same custom converter, just to keep the standard validation through my project to the all kinds of inputs or sorts of.
I already try to use a @ManagaProperty
in a RequestScope
but without success:
@ManagedProperty("#{param.measure}")
private String measure;
So when the blur events occurs it calls my validate
bean which has the requestScope as BalusC said here, but what it comes is a empty string.
Any idea ?