2012-03-11 79 views
1

我有3個豐富的:選擇控件,其中有id select1,select2,select3.I要點擊select1,將控制「select2」呈現,我點擊控件select2,select3會呈現,像這樣。我通過netbeans 7.0.1創建了我的應用程序,並使用框架jsf 2.0和richFaces 4.2.0。兩個豐富:ajax衝突的問題(在3豐富:選擇控件)

我的解決方案是創建兩個ajj:ajax,它們分別具有id ajax1和ajax2,以便根據select1和select2 selectItem事件分配select2和select3基礎的渲染。我將ajax1和ajax2安排在隊列ID爲queue1的隊列中。

這裏是頁面的代碼:遇到

<h:form> 
    <a4j:queue name="queue1" onerror="window.alert('alert in queue');" onrequestdequeue="window.alert('queue1 dequeue');" onrequestqueue="window.alert('queue1 enqueue');" requestDelay="1000" ignoreDupResponses="true"/> 
    <h3 style="text-align: center">Test case 1: 3 selection controls problem</h3> 

    <br/><br/> 
    <h:outputLink value="../index.xhtml">View Index </h:outputLink> 
    <br/><br/> 
    Problem: <h:outputText escape="false" value="#{carBean.testDescription}"/> 
    <br/><br/> 
    <table> 
     <tr> 
      <td>Car Firm (selection1)</td> 
      <td>Car type (selection2)</td> 
      <td>Production (selection3)</td> 
     </tr> 
     <tr> 
      <td> 
     <rich:select id="select1" value="#{carBean.companyName}" maxListHeight="100" enableManualInput="true" defaultLabel="Type here">  
      <a4j:ajax id="ajax1" queueId="queue1" execute="@form" render="select2, errorText" event="selectitem" listener="#{carBean.changeCompanyEvent()}"> 

      </a4j:ajax>         
      <f:selectItems value="#{carBean.lstCompany}"></f:selectItems> 
     </rich:select> 
     </td> 
     <td> 
     <rich:select id="select2" value="#{carBean.typeName}" maxListHeight="100" enableManualInput="true" defaultLabel="Type here" >  
      <a4j:ajax id="ajax2" queueId="queue1" immediate="true" execute="@form" render="select3, errorText" event="selectitem" listener="#{carBean.changeCarTypeEvent()}"> 

      </a4j:ajax>         
      <f:selectItems value="#{carBean.lstCarType}"></f:selectItems> 
     </rich:select> 
     </td> 
     <td> 
     <rich:select id="select3" value="#{carBean.productionName}" 
        maxListHeight="100" enableManualInput="true" defaultLabel="Type here" >            
      <f:selectItems value="#{carBean.lstCarProduction}"></f:selectItems> 
     </rich:select> 
     </td> 
     </tr> 
    </table> 
    <br/><br/> 
    <h:outputText id="errorText" escape="false" value="#{carBean.alertError}"/> 

</h:form> 

問題:我有還是沒有找到原因,但2個問題:

  • 的選擇2必須設置immediate = true,否則在ajax2中定義的事件將不會完成。

我不知道是什麼原因造成的。

  • 當我爲select2設置immediate = true時,調用了ajax2事件。但是,被分配爲select2控件的值的typeName變量仍未選定,因此select3尚未分配一個值。

以下是錯誤圖片:http://i970.photobucket.com/albums/ae190/swenteiger7/richFaces%20error-%20110312/testcase1Error.png

應用:我也把我的應用程序項目(由淨豆IDE中打開)這個問題相處。您可以集中3個項目: - Web/Web-INF文件夾中的faces-config.xml文件,它定義了CarBean管理的Bean - web文件夾中的testcase1文件夾(具有threeSelectExample.xhtml)。 - 用於保存託管bean的beans包和utils包(我們在CarBean託管Bean中隱藏的testcase1中)。

您可以在我的附件文件中下載我的歸檔項目。請加JSF2.0和RichFaces的框架來運行應用程序(https://community.jboss.org/wiki/HowToAddRichFaces4xToProjectsNotBasedOnMaven)

這裏是我的應用程序:http://www.mediafire.com/?fnab3824b8vwd93

如果你有一些問題,下載,請聯繫我。謝謝。

回答

0

我和rich:select有類似的問題。要解決它,我們必須更改爲h:selectOneMenu併爲onchange javascript函數添加ajax功能。此外,當您使用ajax方法時,您應該在h:selectOneMenu中使用valueChangeListener來設置所選值而不是value屬性。

我會告訴你一個樣本

<h:selectOneMenu id="select1" maxListHeight="100" 
    enableManualInput="true" defaultLabel="Type here" 
    valueChangeListener="#{carBean.changeCompanyName}"> 
    <f:selectItems value="#{carBean.lstCompany}"></f:selectItems> 
    <a4j:ajax id="ajax1" queueId="queue1" execute="@form" 
     render="select2, errorText" event="selectitem" 
     listener="#{carBean.changeCompanyEvent()}"> 
</h:selectOneMenu> 

在你ManagedBean,你應該有這樣的代碼:

@ManagedBean(name="carBean") 
@ViewScoped 
public class CarBean implements Serializable { 
    private String companyName; 
    //getters and setter... 
    //constructor and other functions 
    public void valueChangeMethod(ValueChangeEvent e){ 
     companyName = (String)e.getNewValue(); 
    } 
} 

有一個在RichFaces的論壇帖子about this issue。另外,關於populating child menu's的BalusC(JSF專家)博客條目。

+0

非常感謝你的驚人答案。我會檢查它:) – 2012-03-22 20:33:22

+0

你好Luiggi。我在3天前嘗試了您的建議。我仍然不能使用2 ajax事件。當我使用2 時,出現這個問題,不幸的是,在 2012-03-28 19:29:27