简体   繁体   English

用10.000项更新h:selectManyListbox时,Ajax渲染“冻结”一段时间

[英]Ajax rendering “freezes” for a while when updating h:selectManyListbox with 10.000 items

I am using Mojarra JSF (v2.2.10) with Spring (v3.2.5) for a small admin-console on a tomcat (also Twitter Bootstrap for styling). 我正在将Mojarra JSF(v2.2.10)与Spring(v3.2.5)一起用于tomcat上的小型管理控制台(也用于样式的Twitter Bootstrap)。 Basically there is a multiple select box which I can add new entries to via textbox and button. 基本上有一个多重选择框,我可以通过文本框和按钮向其中添加新条目。 I can also remove entries by selecting them and clicking the remove button. 我也可以通过选择条目并单击“删除”按钮来删除条目。

Here is the relevant code piece: 这是相关的代码段:

<h:form>
<h:outputLabel for="selectedEntries" value="Selected entries" />
<h:selectManyListbox id="selectedEntries" value="#{myBean.entriesToRemove}">
  <f:ajax/>
  <f:selectItems value="#{myBean.selectedEntries}" />
</h:selectManyListbox>
<h:commandButton action="#{myBean.addEntriesToSelection}" value="Add">
  <f:ajax render="selectedEntries entriesInput" />
</h:commandButton>
<h:commandButton action="#{myBean.removeEntriesFromSelection}">
  <f:ajax render="selectedEntries entriesInput" />
</h:commandButton>
<h:outputLabel for="entriesInput" value="Input" />
<h:inputTextarea id="entriesInput" value="#{myBean.entriesInput}">
  <f:ajax/>
</h:inputTextarea>

The fields "entriesToRemove" and "selectedEntries" are simple String Lists and the field "entriesInput" is a String. 字段“ entriesToRemove”和“ selectedEntries”是简单的字符串列表,而字段“ entriesInput”是一个字符串。

Everything works just fine, but when the "selectedEntries" list grows to say 10.000 entries, I hit a performance problem: When I try to add a new entry into this overgrown list, the page freezes for about 30 seconds before it renders the updated list. 一切正常,但是当“ selectedEntries”列表增加到说10.000个条目时,我遇到了一个性能问题:当我尝试向这个过度增长的列表中添加新条目时,页面冻结约30秒,然后呈现更新的列表。 。 The same goes for removing an entry. 删除条目也是如此。 This freeze however does not occur in the method "addEntriesToSelection" but rather afterwards, when the backing bean fields are already updated. 但是,此冻结不会在方法“ addEntriesToSelection”中发生,而是在之后更新后备豆字段时发生。 So I assume this has something to do with the rendering of the page. 因此,我认为这与页面的呈现有关。

Does anybody have a clue, how I could solve this problem? 有人知道如何解决这个问题吗? Is this maybe Mojarra- or JSF-specific? 这可能是Mojarra或JSF特有的吗?

This is a client side problem, not a server side problem. 这是客户端问题,而不是服务器问题。 Some browsers, particularly MS Internet Explorer, are known to be laggy when updating the HTML DOM tree with an "insane" amount of new HTML elements. 众所周知,某些浏览器(尤其是MS Internet Explorer)在使用“疯狂”数量的新HTML元素更新HTML DOM树时比较迟钝。 Certainly 10.000 listbox items is "insane". 当然,10,000个列表框项是“疯狂的”。 Google eg also doesn't show all those million potential matches at once when you open the search homepage. 例如,当您打开搜索首页时,Google不会一次显示所有这些潜在的百万匹配项。 Instead, it shows an autocomplete-capable input field allowing you to find and filter the relevant data. 而是显示一个具有自动完成功能的输入字段,可让您查找和过滤相关数据。

Consider turning that listbox into a search/autocomplete input field. 考虑将列表框变成搜索/自动完成输入字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM