简体   繁体   English

如何避免大型JSF视图的部分HTTP响应刷新?

[英]How can I avoid a partial http response flush of large JSF views?

Today I've spend several hours reproducing a very strange UI behavior in our web application using JSF facelets: In some cases the UI was partially rendered in the web browser before the server side really finished rendering the whole view. 今天,我已经花了几个小时使用JSF facelets在我们的Web应用程序中重现非常奇怪的UI行为: 在某些情况下,在服务器端真正完成了整个视图的呈现之前,UI是部分在Web浏览器中呈现的。

In the end it all came down to an JSF view with a large number of elements – in my case items of a submenu. 最后,所有这些都归结为包含大量元素的JSF视图-在我的情况下是一个子菜单项。 There seems to be some threshold that triggers a partial flush of the response. 似乎有一些阈值会触发响应的部分刷新

Here is a minimized example that visually demonstrates that effect: 这是一个最小化的示例,可以直观地演示该效果:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="de" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <style>
        td {
            vertical-align: top;
        }
    </style>
</h:head>
<h:body>

    <h1>EURNEU-10056</h1>

    <table>
        <tr>
            <td>
                <ol>
                    <ui:repeat value="#{bean.strings(10)}" var="str">
                        <li><h:outputText value="#{str}" /></li>
                    </ui:repeat>
                </ol>
                <h:outputText value="#{bean.delay(2000)}" />
            </td>
            <td>
                <ol>
                    <ui:repeat value="#{bean.strings(10)}" var="str">
                        <li><h:outputText value="#{str}" /></li>
                    </ui:repeat>
                </ol>
                <h:outputText value="#{bean.delay(2000)}" />
            </td>
            <td><ol>
                    <ui:repeat value="#{bean.strings(10)}" var="str">
                        <li><h:outputText value="#{str}" /></li>
                    </ui:repeat>
                </ol>
                <h:outputText value="#{bean.delay(2000)}" />
            </td>
        </tr>
    </table>

</h:body>
</html>

That simple view uses the following bean to generate a certain amount of strings and adds some artificial delays into the rendering of 2000ms after each of the 3 columns. 这个简单的视图使用以下bean生成一定数量的字符串,并在3列中的每列之后的2000ms渲染中添加了一些人为的延迟

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Bean implements Serializable {

    private static final long serialVersionUID = 1L;

    public List<String> strings(int count) {
        List<String> all = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            all.add(UUID.randomUUID().toString());
        }
        return all;
    }

    public String delay(int delay) {
        try {
            Thread.sleep(delay);
        }
        catch (InterruptedException ex) {
            // NOP;
        }
        return String.format("This string has been delayed for %d ms!", delay);
    }

}

The browsers shows the following phases while processing the request: 浏览器在处理请求时显示以下阶段:

部分渲染 另一个局部渲染 最终渲染

If I lower the amount of strings used while generating the view the response is only flushed at the very end of the render phase. 如果降低生成视图时使用的字符串数量,则仅在渲染阶段的最后刷新响应。

Is there anything I can do to avoid that partial rendering? 我有什么办法可以避免部分渲染? (other than lowering the number of elements) (除了减少元素数量)

PS: We are using JBoss EAP v7.0.9 as a server. PS:我们正在使用JBoss EAP v7.0.9作为服务器。 The application itself is quite complex. 应用程序本身非常复杂。

It turned our that explizit defining of Facelets buffer-size in web.xml solves that problem. 事实证明,我们在web.xml中明确定义Facelets缓冲区大小解决了该问题。

<!-- We raise the buffer size to avoid partial rendering of complex pages. -->
<context-param>
    <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
    <param-value>1024000</param-value>
</context-param>

That setting and the structure of the generated HTML define the very moment, the browser starts to render the response. 该设置和生成的HTML的结构定义了浏览器就开始呈现响应的那一刻。 In our case the menu was already renderable and showed much earlier than expected. 在我们的情况下,菜单已经可以渲染,并且显示时间比预期的要早得多。

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

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