Problema h:selectOneMenu

0 respostas
F

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
private DataType selectedDataType;
private List<DataType> dataTypes = new ArrayList<DataType>();
...

public List<DataType> getDataTypes() {
		if(dataTypes.size() == 0) {
			try {
	            dataTypes = identificationService.getDataTypesForIdentifications();
            } catch (DEException e) {
	            e.printStackTrace();
            }
		}
		return dataTypes;
    }

Get e set...
Meu converter:
@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;
    }

}
Criado 16 de março de 2012
Respostas 0
Participantes 1