我需要从 <f:selectedItems>
获取 itemValue
这是我的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>
和我的 backingBean 这是我从数据库获取数据
private List<NegaraEntity> listNegara;
private int countryID;
@PostConstruct
public void init()
{
listNegara = negaraRules.getNegara();
}
我想从<f:selectedItem>
获取ID所以我sytem.out.println
像这样
public void test(int ctyId)
{
ctyId = countryID;
System.out.println(ctyId);
}
但这不起作用,有什么想法吗?
感谢您的帮助。
最佳答案
问题出在方法public void test(int ctyId)
,因为它有一个参数int ctyid
JSF 必须说:javax.el.MethodNotFoundException
更改为 public void test()
请记住,应用请求值阶段发生在调用应用程序阶段之前,因此在执行方法时已设置 #{propinsiBacking.countryID}
.
关于java - 如何从 selectonemenu JSF 获取项目值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46555771/