2

下午好,

我有一个搜索页面,它使用 ajax 来呈现几个数据表而不刷新页面。我必须为每个表调用一个方法作为侦听器。下面是第一个工作正常的数据表的片段。

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

所以剩下的方法就是调用<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" >....

我仍然不确定为什么复合方法在调用时不起作用。可能在正确阶段之前或之后没有调用它(稍后我将对其进行分析)。无论如何,我找到了一个有两条边的解决方案(它解决了我的问题,但让我牺牲了 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/>.

如果有人有允许使用属性操作侦听器和ajax来避免使用按钮提交表单的解决方案,那么欢迎他/她。我会让他/她的回答被接受。

4

1 回答 1

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/>.

如果有人有允许使用属性操作侦听器和ajax来避免使用按钮提交表单的解决方案,那么欢迎他/她。我会让他/她的回答被接受。

于 2011-06-23T21:17:46.350 回答