Problème avec selectOneMenu
salut tout le monde j'utilise JSF 2 et j'ai un problème avec mon selectOneMenu
le but c'est d'afficher une liste de produits et de choisir un seul et de l’envoyé via un commande bouton . la récupération des donné ce fait exactement comme je veux:lol::lol: mais quand je sélectionne un produit et je Click sur bouton valider rien ne se passe voila mon code : xhtml
Code:
1 2 3 4 5 6 7 8
|
<h:outputLabel>Produit </h:outputLabel>
<h:selectOneMenu effect="fade" value="#{produitMB.selectedProduit}" converter="#{ProduitConvert}">
<f:selectItem itemLabel="Produits" itemValue="" />
<f:selectItems value="#{produitMB.produits}" var="produit" itemLabel="#{produit.designation}" itemValue="#{produit}"/>
</h:selectOneMenu>
<p:commandButton actionListener="#{produitMB.save}"
value="valider" update="dataTable"/> |
Managed bean
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
public class ProduitMB extends AbstractMB{
private List<Produit> produits;
private Section selectedProduit;
public CourrierMB(){
//apartir de la db
produits = facade.getAllProduit()
}
public void save(ActionEvent actionEvent) {
//traitement
//.............
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO,
"Ajout effectué avec succée","!!!"));
}
} |
mon convert
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
@FacesConverter(forClass = com.package.Produit.class)
public class ProduitConvert implements Converter{
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
ProduitDao ProduitDao = new ProduitDao();
int idProduit;
try {
idProduit= Integer.parseInt(arg2);
} catch (NumberFormatException exception) {
throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Type the label of a produit and select it (or use the dropdow)", "Type the name of a idProduit and select it (or use the dropdow)"));
}
return produitDao.find(idProduit);
}
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
if (arg2 == null) {
return "";
}
Produit produit = (Produit) arg2;
return String.valueOf(produit.getIdProduit());
}
} |