如何使用 JSF
发布于 2024-11-16 12:51:50 字数 1553 浏览 5 评论 0 原文

下午好,

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

要渲染第二个数据表,我需要调用方法 #{evalController.prepareList} 作为 ajax 的侦听器。问题是 "Listener" 属性不会采用多个方法

所以剩下的方法是多次调用,并且每次使用不同的监听器,这是行不通的。有办法实现这一点吗? 如果不是,我是否应该在托管 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" >....

Good Afternoon,

I have a search page that uses ajax to render a several datatables without refreshing the page.
It is mandatory for me to call a Method as a Listener for each table.
Below is the snippet for the first datatable that works fine.

To render a second datatable I need to call a method #{evalController.prepareList} as a Listener for the ajax. The problem is that <f:ajax "Listener" attribute won't take more than one method.

So the remaining way is to call <f:ajax several times, and each time with a different listener, which does not work. Is there a way to achieve this?
If not, should I create a method in the managed Bean that calls all the methods that I need and use it as the one listener?
Thanks in advance for your help.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-11-23 12:51:50

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

我希望 可以嵌套在 .

如果有人有一个允许使用属性操作侦听器ajax以避免使用按钮提交表单的解决方案,欢迎他/她。我将接受他/她的回答。

I am still not sure why the composite method do not have effect when called. Probably it is not called during before or after the right phase (I'll be profiling it later). Anyway, I found a solution with two edges (it is solving my problem but makes me sacrifice the use of ajax) :

So Instead of calling - from each managed bean - the method (prepareList()) which I use as listener:

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

(by the way, this method sets the datamodel to NULL to refresh it, and that is how my datatables get refreshed).
Inside the command button I nested property action listener:

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

I wish <f:PropertyActionListener /> could be nested inside <h:ajax/>.

If somebody has a solution that allows to use property action listener and ajax to avoid submitting the form with a button, s/he is welcome. I'll make then his/her answer as accepted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文