我已经就这个话题做了几个答案,尤其是来自BalusC的博客。但它在某种程度上不适用于下面的实现。我错过了什么或做了一些完全错误的事情。
我有一个带有几个下拉列表的基本表单,当我提交表单时,即调用submitDetails
,它返回以下由"phaseTwo?faces-redirect=true"
PhaseTwoController.java
因此,在phaseOne.xhtml
提交时,我希望看到phaseTwo.xhtml
上phaseOne.xhtml
选择的值<{1}}
以下是代码:
这是由PhaseOne.xhtml
PhaseOneController.java
<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="subCategory" />
<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.submitDetails}" icon="ui-icon-check">
<f:param name="country" value="#{phaseOneController.country}" />
<f:param name="province" value="#{phaseOneController.province}" />
<f:param name="city" value="#{phaseOneController.city}" />
</p:commandButton>
</p:panel>
</h:form>
@ManagedBean
@RequestScoped
public class PhaseTwoController {
@ManagedProperty(value="#{param.country}")
private String country;
@ManagedProperty(value="#{param.province}")
private String province;
public void setCountry(String country) {
this.country = country;
}
public void setProvince(String province) {
this.province = province;
}
public void setCity(String city) {
this.city = city;
}
}
P.S。我没有发布PhaseOneController.java的代码,因为我不确定是否需要它。但如果有人想看,我可以发布。