2017-10-04 2 views
2

j'ai besoin de ItemValue obtenir de <f:selectedItems>Comment ItemValue obtenir de selectonemenu JSF

c'est mon xhtml

<h:form> 
<h:panelGrid columns="3" cellpadding="5"> 
    <p:outputLabel for="negara" value="Negara"></p:outputLabel> 
    <p:selectOneMenu id="negara" value="#{propinsiBacking.countryID}"> 
     <f:selectItems value="#{propinsiBacking.listNegara}" var="negara" itemLabel="#{negara.countryName}" itemValue="#{negara.countryID}"></f:selectItems> 
    </p:selectOneMenu> 
    <p:commandButton value="Go" action="#{propinsiBacking.test}"></p:commandButton> 
</h:panelGrid> 
</h:form> 

et mon backingBean c'est-je obtenir des données de base de données

private List<NegaraEntity> listNegara; 
private int countryID; 
@PostConstruct 
public void init() 
{ 
    listNegara = negaraRules.getNegara(); 
} 

et je veux obtenir l'ID de <f:selectedItem> donc je sytem.out.println comme ça

public void test(int ctyId) 
{ 
    ctyId = countryID; 
    System.out.println(ctyId); 
} 

mais cela ne fonctionne pas, aucune idée?

merci pour l'aide.

Répondre

2

Le problème est la méthode public void test(int ctyId) parce qu'il a un param int ctyid

JSF doit dire: javax.el.MethodNotFoundException

Modification public void test() rappeler que les valeurs demande phase d'application se produit avant la phase d'invoquer l'application, si #{propinsiBacking.countryID} est déjà défini lorsque la méthode est exécutée.

+0

merci :-) il a travaillé – Pyon

0

changement test public void être

public String test() 
{ 
    System.out.println(countryID); 
    return "null"; 
}