2013-12-15 22 views
0

我有兩個p:selectOneMenu,一個是區域和其他是區域,如果區域被選中,那麼它應該自動選擇相應的區域,區域和區域都從數據庫表和區表包含Zone_id。即Zone可以使用zone_id從區域訪問。控制選擇一個p:selectOneMenu從其他p:selectOneMenu在底數

加載表單時加載區域和區域。 如何在Primefaces中實現此功能?我在Java中完成了相同的工作,但在Primefaces中沒有完成。

+0

我試圖讀取district_id獲取zone_id,然後找到區域表中的區域,但不知道如何顯示在p:selectOneMenu。 – SudeepShakya

回答

0

你可以試試這個例子作爲其工作的罰款,我們可以使用兩個以上的selectOneMenu用於如果我們希望它是可靠的另一個

page.xhtml

<h:outputLabel value="Country"></h:outputLabel> 
     <p:selectOneMenu value="#{someBean.countryId}" style="width:157px;"> 
      <f:selectItem itemLabel="Select Country" itemValue="" /> 
      <f:selectItems value="#{someBean.countryList}" var="country" 
       itemLabel="#{country.name}" itemValue="#{country.id}" /> 
      <p:ajax update="State" listener="#{someBean.coutChange}" /> 
     </p:selectOneMenu> 

    <h:outputLabel value="State"></h:outputLabel> 
     <p:selectOneMenu value="#{someBean.stateId}" id="State" style="width:157px;"> 
      <f:selectItem itemLabel="Select State" itemValue="" /> 
      <f:selectItems value="#{someBean.stateList}" var="state" 
      itemLabel="#{state.name}" itemValue="#{state.id}" /> 
     </p:selectOneMenu> 

在Bean類使用數組數據庫中的類型對象列表,並創建getter/setter和getter寫入查詢以從數據庫中獲取數據。爲selectOneMenu標記的值屬性創建selectOneMenu中所選值的變量。然後在監聽器的p:ajax標籤中寫入一個方法來檢查coutryId,如果不返回基於countryId的狀態列表,則返回null。這應該希望它可以幫助你

相關問題