Richfaces 4.5.0 - converter in rich:select
laurent.hever Nov 6, 2014 6:16 AMHi,
I found the following "problem".
I have a rich:select with some values an a "default" value which is null.
When I select a "valid" value and then want to go back to the "null" value, the converter isn't invoked.
However when I replace the rich:select component with a h:selectOneMenu, everything is working as excpected.
here my code (this one is working)
<h:selectOneMenu defaultLabel="Veuillez sélectionner"
id="slcAnnee"
style="width: 100px;"
converter="#{saisonConverter}"
value="#{sessionDataBean.currentSelectedSaison}" >
<f:selectItem itemLabel="---" itemValue="#{null}" noSelectionOption="true"/>
<f:selectItems value="#{saisonFacade.all}"
var="saison"
itemLabel="#{saison.libelle}"
itemValue="#{saison}"/>
<f:ajax event="change" render="tblIntervention saison" execute="@this"/>"
</h:selectOneMenu>
Here my Abstract Vonverter class which i am extending
public abstract class AbstractDbObjectConverter implements Converter {
@PersistenceContext
private EntityManager em;
public abstract Class getEntityClass();
public Object getAsObject(FacesContext facesContext, UIComponent component, String id) {
try {
return em.find(getEntityClass(), Long.parseLong(id));
} catch (IllegalArgumentException ignored) {
}
return null;
}
public String getAsString(FacesContext facesContext, UIComponent component, Object obj) {
if (obj == null) return null;
if (obj instanceof String && ((String) obj).trim().length() == 0) return null;
if (obj instanceof DBObject) {
return ((DBObject) obj).getId().toString();
}
return null;
}
}
here is the actual converter
@Model
public class SaisonConverter extends AbstractDbObjectConverter {
@Inject
private Logger log;
public Class getEntityClass() {
return Saison.class;
}
@PersistenceContext
private EntityManager em;
@Override
public Object getAsObject(FacesContext facesContext, UIComponent component, String id) {
log.info("getAsObject...");
log.info("getAsObject.id: >"+id+"<");
try {
return em.find(getEntityClass(), Long.parseLong(id));
} catch (NumberFormatException nfe) {
log.info("NumberFormatException: " + nfe);
} catch (NoResultException nre) {
log.info("NoResultException: " + nre);
}
return null;
}
}
Thanks for any suggestion,
Laurent