刷新组元素 [英] Refresh group of elements

查看:92
本文介绍了刷新组元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF页面,它基本上只是数据的行和列。每行的数据来自类实例的属性。每行都有一个链接,当单击它时调用一个支持bean方法,该方法刷新该行上的数据。行由标题分隔,标题代表它们下面的行组。我想让标题成为一个链接,这样它就会刷新它下面的所有行。我尝试使用这样的一些JavaScript:

I have a JSF page which is essentially just rows and columns of data. Each row's data comes from the attributes of an instance of a class. Each row has a link on it that when clicked calls a backing bean method which refreshes the data on that row. The rows are separated by headings which represent the group of rows beneath them. I want to make the heading a link as well, so that it will refresh all of the rows beneath it. I tried using some javascript like this:

function refreshGroup(){
  var obj1 = document.getElementById("refresh0:link0");
  var obj2 = document.getElementById("refresh1:link1");
  window.open(obj1);
  window.open(obj2);
 };

但这只是打开了新标签。有没有办法让它像用户点击每个链接一样?这就是JSF对调用支持bean的链接的看法:

but that just opened new tabs. Is there any way to make it act as though the user clicked on each of the links? This is what the JSF looks like for the link that calls the backing bean:

<h:form id="refresh#{loop.index}" >
  <h:commandLink id="link#{loop.index}" value="#{a.status}" >
    <f:ajax listener="#{a.getCheckAppMonitor}" 
            render=":errs#{loop.index} :refresh#{loop.index} :errs_#{i+1}"
            onevent="refreshMoreLessLinks" />
  </h:commandLink>&nbsp;<img id="img_#{loop.index}" 
                             class="hidden" 
                             src="resources/images/ajax-loader.gif"/>
</h:form>

这些都嵌套在 c:foreach loop。

This is all nested inside of a c:foreach loop.

标题链接如下所示:

<h3><a href="javascript:refreshGroup();">Group 1</a></h3>

编辑:

它发生在我身上我需要创建一个 commandLink ,这样我就可以再次渲染所有内容。我这样做了:

It occurred to me that I need to create a commandLink so I can render everything again. I did this:

<h:form id="header1" >
  <h:commandLink class="link" value="Group 1" >
    <f:ajax listener="#{appBean.refresh}" render="@all" />
  </h:commandLink>
 </h:form>

它似乎有效,只是它导致我的浏览器(IE8)崩溃。当浏览器恢复时,我可以看到它确实更新了。关于render =@ all的任何想法都会导致我的浏览器崩溃?我将@all更改为一个元素并且工作正常。

and it seems work, only it causes my browser (IE8) to crash. When the browser recovers, I can see that it did in fact update. Any ideas on what render="@all" is causing my browser to crash? I changed @all to one element and it worked fine.

推荐答案

这个,

var obj1 = document.getElementById("refresh0:link0");
window.open(obj1);

不是触发 HTMLAnchorElement 实例。你需要调用它的 click()方法。

var obj1 = document.getElementById("refresh0:link0");
obj1.click();

这篇关于刷新组元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆