【发布时间】:2012-03-11 23:14:07
【问题描述】:
我有 3 个 Rich:select 控件,id 分别为 select1、select2、select3。我想单击 select1,将呈现控件“select2”,当我单击控件 select2 时,将呈现 select3,如下所示。我通过 netbeans 7.0.1 制作了我的应用程序,并使用了框架 jsf 2.0 和richFaces 4.2.0。
我的解决方案是创建两个具有 id ajax1 和 ajax2 的 a4j:ajax,根据 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个问题还没找到原因:
- select2 必须设置 immediate = true,否则 ajax2 中定义的事件不会完成。
我不知道这是什么原因。
- 当我为 select2 设置 immediate = true 时,调用了 ajax2 事件。但是作为select2控件赋值的typeName变量仍然没有赋值,所以select3还没有赋值。
这是错误图片:http://i970.photobucket.com/albums/ae190/swenteiger7/richFaces%20error-%20110312/testcase1Error.png
应用程序:我还发送了我的应用程序项目(由 net beans IDE 打开)来解决这个问题。你可以专注于3个项目: - Web/Web-INF 文件夹下的 faces-config.xml 文件,定义了 CarBean 管理的 Bean - web 文件夹中的 testcase1 文件夹(其中包含三个SelectExample.xhtml)。 - beans 包和 utils 包保存托管 bean(在 testcase1 中我们关注 CarBean 托管 Bean)。
您可以在我的附件中下载我的存档项目。请添加 JSF2.0 和richFaces 框架来运行应用程序(https://community.jboss.org/wiki/HowToAddRichFaces4xToProjectsNotBasedOnMaven)
这是我的申请:http://www.mediafire.com/?fnab3824b8vwd93
如果下载有问题,请联系我。谢谢。
【问题讨论】: