Custom converter Error in h:SelectOneMenu
I have a problem implementing a custom converter...
my xhtml is:
...
<span class="cien">
<h:outpu开发者_如何学JAVAtLabel value="Director de Area Correspondiente:"
styleClass="negritas" />
<h:selectOneMenu value="#{ordenBO.director}" id="director-area"
converter="superiorAuditoriaConverter"
converterMessage="Error al seleccionar el Director">
<f:selectItems value="#{ordenBO.directores}"></f:selectItems>
</h:selectOneMenu>
<p:message for="director-area"></p:message>
</span>
...
this is how I fill my h:SelectOneMenu:
...
this.directores = new ArrayList<SelectItem>();
for (SuperiorAuditoriaDTO sup: daoSuperiorAuditoria.getDirectoresASM())
this.directores.add(new SelectItem(sup, sup.getProfesion() + " " +
sup.getNombre_completo()));
...
this is my Custom converter:
....
@FacesConverter(forClass = SuperiorAuditoriaDTO.class, value =
"superiorAuditoriaConverter")
public class SuperiorAuditoriaConverter implements Converter {
private static SuperiorAuditoriaDAO dao = new SuperiorAuditoriaDAO();
public Object getAsObject(FacesContext arg0, UIComponent arg1, String id_persona) {
SuperiorAuditoriaDTO s = null;
try {
s = dao.getSuperiorASM(Integer.parseInt(id_persona));
} catch(Exception e) {
e.printStackTrace();
}
return s;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object auditor) {
return String.valueOf(((SuperiorAuditoriaDTO) auditor).getId_persona());
}
}
Can somebody help me?? I always got an error message saying that the value that I try to convert is not valid..
I'm using jsf 2 mojarra... and I also have equals and hashCode method implemented...
thanks..
I always got an error message saying that the value that I try to convert is not valid.
Thus, you got "Validation error: Value not valid"? That will happen when the equals()
method on the selected object has not returned true
for any of the available select items. In other words, the equals()
method of SuperiorAuditoriaDTO
is broken. Fix it accordingly.
See also:
- Right way to implement equals contract
精彩评论