2011-06-22 28 views
1

下午好,如何使用JSF <f:ajax listener调用几个方法?

我有一个使用AJAX来呈现几个数据表而无需刷新页面搜索页面。 对于每个表格,我都必须调用Method作为侦听器。 下面是第一个可正常工作的数据表的代码片段。

要呈现第二个数据表,我需要调用方法#{evalController.prepareList}作为ajax的侦听器。问题是<f:ajax“听众”属性不会采取多个方法

所以余下的方法是拨打<f:ajax几次,每次都有一个不同的监听器,这是行不通的。有没有办法做到这一点? 如果不是,我应该在托管Bean中创建一个方法来调用我需要的所有方法并将其用作一个侦听器? 在此先感谢您的帮助。

<h:form id="searchform"> 

       <h:panelGrid columns="3" > 
        <p:inputText value="#{ddnController.patientID}" id="pidinput" maxlength="7" size="7"> 
         <f:ajax execute="@this" event="keyup" render="searchbutton ddntable" listener="#{ddnController.prepareList}"/> 

        </p:inputText> 

        <h:commandButton image="#{resource['images/search.png']}" id="searchbutton" value="#{bundle.Search}" 
             action="submit" actionListener="#{ddnController.prepareList}" 
             disabled="#{empty ddnController.patientID or ddnController.patientID.equals('0')}"/> 
        <p:panel><h:outputText value="Saisir 0 pour avoir tous les Patients" style="font-style: italic;"/></p:panel> 
       </h:panelGrid> 

       <p:dataTable id="ddntable" value="#{ddnController.items}" var="ddn" rendered="#{!empty ddnController.items}" paginator="true" >.... 
+2

如何使用复合函数调用其中的多个其他函数。 –

+2

所以很明显,我_almost_没有投票发表您的评论。 –

+0

@Marcos @Steve Taylor谢谢您的意见。我问这个问题的原因是,我想确保没有办法只在视图中进行操作,而不在托管bean中游泳。 我的问题实际上是我确实创建了一个方法(函数),它调用我需要在ajax事件期间调用的所有其他函数并用作ajax监听器:public void prepareAllLists(ActionEvent event){ddrController = new DdnController(); ddnController.prepareList(); evalController = new .... evalController.prepareList(); ...... }'但它不起作用,虽然它被称为。 – Hanynowsky

回答

0

我仍不确定为什么复合方法调用时没有效果。可能它在正确的阶段之前或之后没有被调用(我将在以后进行分析)。无论如何,我发现两个边的解决方案(这是解决我的问题但让我牺牲使用Ajax的):

因此而不是调用的 - 从每个托管bean - 方法(prepareList( )),我为收听使用:

private DataModel items = null; // Getter to retrieve items 
    // ...... 
    public String prepareList() { 
    recreatemodel(); 
    return "List"; 
    } 
private void recreatemodel(){ 
items=null; 
} 

(顺便说一句,这种方法将数据模型来NULL刷新它,这是我的数据表怎么弄刷新)。 里面的命令按钮我嵌套属性的动作监听:

<h:commandButton image="#{resource['images/search.png']}" id="searchbutton" value="#{bundle.Search}" 
             action="submit" 
             disabled="#{empty ddnController.patientID or ddnController.patientID.equals('0')}"> 

<f:PropertyActionListener target="#{ddnController.items}" value="#{null}" /> 
<f:PropertyActionListener target="#{evalController.items}" value="#{null}" /> 
<f:PropertyActionListener target="#{corController.items}" value="#{null}" /> 
<!--...etc --> 

</h:commandButton> 

我希望<f:PropertyActionListener />可以嵌套在<h:ajax/>.

如果有人有一个解决方案,允许使用财产的动作监听阿贾克斯避免用一个按钮提交表格,欢迎他/她。我会把他/她的回答作为接受。

+0

@Marcos @Steve Taylor如果有人有一个解决方案,允许使用属性动作监听器和ajax来避免提交表单的按钮,他/她是受欢迎的。我会把他/她的回答作为接受。 – Hanynowsky