2009-10-23 53 views
0

我正在嘗試在a4j:repeat內放置幾個下拉菜單。第二個下拉列表的值取決於第一個選擇的值。下面是我嘗試使用的代碼,但它傳遞一個空參數:如果我改變的F在Richfaces a4j內發送JSF參數:重複

<a4j:repeat id="localRepeat" var="local" value="#{InstanceController.instance.locations}" rowKeyVar="row"> 
        <h:panelGrid columns="2"> 
         <h:outputLabel value="Theater:" /> 
         <h:selectOneMenu id="theater" converter="#{TheaterConverter}" value="#{local.theater}"> 
          <f:selectItems id="theaters" value="#{InstanceController.allTheaters}" /> 
          <a4j:support event="onchange" action="#{InstanceController.getAllCountriesInTheater}" reRender="country" > 
           <f:param name="theater" value="#{local.theater.id}"/> 
          </a4j:support> 
         </h:selectOneMenu> 

         <h:outputLabel value="Country:" /> 
         <h:selectOneMenu immediate="true" id="country" converter="#{CountryConverter}" value="#{local.country}"> 
          <f:selectItems value="#{InstanceController.allCountriesInTheater}" /> 
          <a4j:support event="onchange" reRender="state" /> 
         </h:selectOneMenu> 

        </h:panelGrid> 
        <rich:spacer height="10px" /> 
       </a4j:repeat> 

:參數去發送「1」,而不是「#{} local.theater.id」它的工作原理如預期。

有沒有辦法讓第一個下拉菜單的選定值下載並作爲參數發送?

回答

2

此原因不起作用的是,當呈現f:param標記時,local.theater.id的當前值已被分配給該參數。因此,劇院參數將包含在頁面呈現時選擇的劇院ID - 可能爲null,因爲尚未選擇劇院。

你要做的事情要容易得多: 只需刪除f:param並直接使用屬性即可。當a4j:support標籤由於選擇框值發生更改而觸發時,jsf將驗證您的表單標籤並分配適當的模型值。所以,當getAllCountriesInTheater動作被執行時,local.theater屬性將已經包含選定的影院。

根據您的支持豆的設計方式,您可能需要一個參數來標識選擇框已更改的位置,因此getAllCountriesInTheater操作將知道要在哪個位置查找所選影院。