【发布时间】:2016-10-17 04:40:06
【问题描述】:
我有一个简单的 JSF 表单,其中包含三个下拉菜单, 这是代码:
<h:form>
<p:panel header="Select country" style="margin-bottom:10px;">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="country" value="Country: " />
<p:selectOneMenu id="country" value="#{phaseOneController.country}" style="width:150px">
<p:ajax listener="#{phaseOneController.onCountryChange}" update="province" />
<f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.countries}" />
</p:selectOneMenu>
<p:outputLabel for="province" value="Province: " />
<p:selectOneMenu id="province" value="#{phaseOneController.province}" style="width:150px">
<p:ajax listener="#{phaseOneController.onProvinceChange}" update="city" />
<f:selectItem itemLabel="Select Province" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.provinces}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="City: " />
<p:selectOneMenu id="city" value="#{phaseOneController.city}" style="width:150px">
<f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.cities}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator />
<p:commandButton value="Select" actionListener="#{phaseOneController.submit}" icon="ui-icon-check">
</p:commandButton>
</p:panel>
</h:form>
现在,当我选择一个国家/地区时,会调用 onCountryChange,但是当我更新省份时,根本不会调用 onProvinceChange!令人惊讶的是,一个人会工作而另一个人不会
这是来自控制器的一段代码:
public void onCountryChange() {
System.out.println("On country change called");
}
public void onProvinceChange() {
System.out.println("On province change called");
}
为了缩短问题,我替换了侦听器方法中的代码。
回答:For anyone who faces this issue, using HashMap to populate the dropdown solved the issue. I am not sure why list is giving so much trouble.
【问题讨论】:
-
phaseOneController bean的作用域是什么?
-
它的 RequestScoped
-
<p:ajax listener="#{phaseOneController.onCountryChange}" update="subCategory" />中的更新永远不会起作用 -
@Kukeltje Well its update="province"
标签: jsf primefaces jsf-2