Boa tarde
Estou tentando usar h:selectOneMenu com um objeto como retorno, porém ele sempre retorna null, segue:
<h:selectOneMenu id="#{msgs.id_type}" style="width: 140px;" value="#{identificationBean.selectedDataType}" required="true" converter="#{dataTypeConverter}">
<f:selectItem itemLabel="#{msgs.id_chooseOne}" itemValue="" noSelectionOption="true"/>
<f:selectItems value="#{identificationBean.dataTypes}" var="data" itemLabel="#{data.name}" itemValue="#{data}"/>
</h:selectOneMenu>
BackBean[code]private DataType selectedDataType;
private List dataTypes = new ArrayList();
…
public List getDataTypes() {
if(dataTypes.size() == 0) {
try {
dataTypes = identificationService.getDataTypesForIdentifications();
} catch (DEException e) {
e.printStackTrace();
}
}
return dataTypes;
}
Get e set…[/code]
Meu converter:[code]@Component(value=“dataTypeConverter”)
public class DataTypeConverter implements Converter{
@Autowired
private IdentificationService identificationService;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if(value != null){
try {
List<DataType> list = identificationService.getDataTypesForIdentifications();
for(DataType dataType : list){
if(dataType.getName().equals(value))
return dataType;
}
} catch (DEException e) {
e.printStackTrace();
}
}
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if(value != null && value instanceof DataType) {
return ((DataType)value).getName();
}
return null;
}
}[/code]