Reputation: 97
i need to get itemValue from <f:selectedItems>
this is my 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>
and my backingBean this is i get data from database
private List<NegaraEntity> listNegara;
private int countryID;
@PostConstruct
public void init()
{
listNegara = negaraRules.getNegara();
}
and i want to get id from <f:selectedItem>
so i sytem.out.println
like this
public void test(int ctyId)
{
ctyId = countryID;
System.out.println(ctyId);
}
but this not working,any idea?
thanks for the help.
Upvotes: 2
Views: 530
Reputation: 97
change public void test be
public String test()
{
System.out.println(countryID);
return "null";
}
Upvotes: 0
Reputation: 1281
The problem is the method public void test(int ctyId)
because it have a param int ctyid
JSF must say: javax.el.MethodNotFoundException
Change to public void test()
remember that apply request values phase occurs before invoke application phase, so #{propinsiBacking.countryID}
is already set when method is executed.
Upvotes: 2