I have a probleme in SelectOneMenu in my accueil.jsf page
xhtml page:
<h:outputText value="Code type opération : " />
<h:selectOneMenu id="op" value="#{mainController.operation}">
<f:selectItem itemLabel="Choisir Code Opération "
itemValue="#{null}" noSelectionOption="true" />
<f:selectItems value="#{mainController.listeTypeOperations}" />
<f:converter converterId="TypopConverter" />
</h:selectOneMenu>
Converter class:
public class TypOpConverter implements Converter {
@Override
public Object getAsObject(FacesContext facesContext,
UIComponent component,
String value) {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("spring-web.xml");
BanqueService banqueService =
(BanqueService)context.getBean("banqueService");
TypeOperation typop;
if (value == null) {
typop = null;
} else {
Long id = new Long(value);
typop = banqueService.getTypeOperationParId(id);
if (typop == null) {
return null;
}
}
return typop;
}
@Override
public String getAsString(FacesContext facesContext,
UIComponent component,
Object value) {
if (value == null) {
return "";
}
if (value instanceof String) {
return (String) value;
}
return String.valueOf(((TypeOperation) value).getId());
}
}
My managed Bean and Controller
@ManagedBean(name="mainController")
@ViewScoped
public class MainController implements Serializable{
private TypeOperation operation;
// get and set
public List<TypeOperation> getListeTypeOperations(){.....}
The converter run and i did some print to show the string and object but the selected value can't be stored into #{mainController.operation}
i think
the error:
j_idt7:op: Validation Error: Value is not valid