如何使用p:ajax将p:selectOneMenu中的值传递给托管bean并将其返回视图
xhtml代码:如何使用p:ajax将p:selectOneMenu中的值传递给托管bean并将其返回视图,ajax,jsf-2,primefaces,Ajax,Jsf 2,Primefaces,xhtml代码: <p:selectOneMenu id="destinationCountryId" style="width:150px" value="#{trafficMBean.traffic.destinationCountryId}" required="true" requiredMessage="Destination Country is required" > <f:selectItem itemLabel="Select" ite
<p:selectOneMenu id="destinationCountryId" style="width:150px" value="#{trafficMBean.traffic.destinationCountryId}" required="true" requiredMessage="Destination Country is required" >
<f:selectItem itemLabel="Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{trafficMBean.countries}" var="country" itemLabel="#{country.countryname}" itemValue="#{country.id}" />
<p:ajax event="change" process="@this" listener="#{trafficMBean.getCountrySpecificBranchList}" immediate="true"/>
</p:selectOneMenu>
<p:outputLabel for="destinationBranchId" value="Destination Branch: "/>
<p:selectOneMenu id="destinationBranchId" style="width:150px" value="#{trafficMBean.traffic.destinationDsvBranchId}">
<f:selectItem itemLabel="Select" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{trafficMBean.branches}" var="branch" itemLabel="#{branch.branchname}" itemValue="#{branch.id}" />
</p:selectOneMenu>
//并将更新后的分支列表发送到JSF页面
//int cid=traffic.getDestinationCountryId();
//debug(“AJAX调用离开TrafficMBean getCountrySpecificBranchList方法::选定的国家Id为::>”+cid)}
我应该如何从JSF中获取所选的country下拉列表值,并将其传递给托管bean。在托管bean中获取和处理之后,我应该如何在JSF中获取更新的值并将其返回到分支select标记中。这就是
p:selectOneMenu
的value
属性应该用于…在您的国家/地区下拉列表中,在您的p:ajax添加update=“destinationBranchId”。在方法getCountrySpecificBranchList
中,您需要填写分支下拉列表,并将这些值存储在Branchs
变量中。。。
public void getCountrySpecificBranchList(AjaxBehaviorEvent e){
logger.debug("AJAX called Inside TrafficMBean getCountrySpecificBranchList method component is "+e.getComponent());
int i = (Integer)((UIOutput)e.getSource()).getValue();
logger.debug("AJAX called Inside TrafficMBean getCountrySpecificBranchList method source is "+i);
logger.debug("AJAX called Inside TrafficMBean getCountrySpecificBranchList method string is "+e.toString());
//Need to process my country ID and get only those branches which are there for this country.