流内容到JSF UI [英] Streaming content to JSF UI

查看:46
本文介绍了流内容到JSF UI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对JSF应用程序感到非常满意,该应用程序读取接收到的MQ消息的内容并将其提供给UI,如下所示:

I was quite happy with my JSF app which read the contents of MQ messages received and supplied them to the UI like this:

<rich:panel>
<snip>
  <rich:panelMenuItem label="mylabel"  action="#{MyBacking.updateCurrent}">
    <f:param name="current" value="mylog.log" />    
  </rich:panelMenuItem>
</snip>
</rich:panel>

<rich:panel>
  <a4j:outputPanel ajaxRendered="true">
    <rich:insert content="#{MyBacking.log}" highlight="groovy" />
  </a4j:outputPanel>
</rich:panel>

和MyBacking.java

and in MyBacking.java

private String logFile = null;
...

    public String updateCurrent() {
        FacesContext context=FacesContext.getCurrentInstance();
        setCurrent((String)context.getExternalContext().getRequestParameterMap().get("current"));
        setLog(getCurrent());
        return null;
    }

    public void setLog(String log) {
        sendMsg(log);
        msgBody = receiveMsg(moreargs);
        logFile = msgBody;
    }

    public String getLog() {
        return logFile;
    }

直到其中一条消息的内容太大并且tomcat摔倒了.显然,我认为,我需要更改其工作方式,以便返回某种形式的流,从而使任何一个对象都不会变得太大,以至于容器消失,并且连续消息返回的内容在传入时将流传输到UI.

until the contents of one of the messages was too big and tomcat fell over. Obviously, I thought, I need to change the way it works so that I return some form of stream so that no one object grows so big that the container dies and the content returned by successive messages is streamed to the UI as it comes in.

我是正确的想法,认为我可以用BufferedOutputStream对象替换现在在String对象上所做的工作,即,无需更改JSF代码,并且在后端进行如下更改:

Am I right in thinking that I can replace the work I'm doing now on a String object with a BufferedOutputStream object ie no change to the JSF code and something like this changing at the back end:

private BufferedOutputStream logFile = null;

    public void setLog(String log) {
        sendMsg(args);
        logFile = (BufferedOutputStream) receiveMsg(moreargs); 
    }

    public String getLog() {
        return logFile;
    }

推荐答案

如果Tomcat失败了,它必须超过128MB或两倍(这是某些Tomcat版本的最小默认内存大小).我认为用户不会喜欢访问这么大的网页.在本地主机上同时充当服务器和客户端时,感觉可能很快,但通过Internet提供服务时,速度可能会慢100倍.

If Tomcat fell over that, it must be over 128MB large or maybe double (which is the minimum default memory size of certain Tomcat versions). I don't think that users would value to visit a webpage which is that big. It may feel fast when acting as both server and client at localhost, but it will be up to 100 times slower when served over internets.

介绍分页/过滤.查询并一次仅显示100个条目.添加一个返回特定结果的过滤器,例如特定时间范围或特定用户的日志等.

Introduce paging/filtering. Query and show just 100 entries at once or so. Add a filter which returns specific results, such as logs of a certain time range or of certain user, etc.

Google也不会一次在一个网页上显示所有不计其数的可用结果,它们的服务器也肯定会掉下来":)

Google also doesn't show all the zillion available results at once in a single webpage, their servers would certainly "fell over" as well :)

更新,其注释如下:Bean是否已放置在会话范围内?这样,它的确会很快在内存中累积.仅当一侧有InputStream而另一侧有OutputStream时,才可以进行流传输.没有任何一种方法可以像尝试转换那样将String转换为流,从而不再将其存储在Java内存中.源必须留在另一端,并且必须通过该行逐字节地进行检索.唯一可行的方法是使用<iframe>,其src指向某个HttpServlet,该HttpServlet直接将数据从源流传输到响应.

Update as per the comment: Is the bean been put in the session scope or so? This way it will indeed accumulate in the memory soon. Streaming is only possible if you have an InputStream at the one side and an OutputStream at the other side. There is no way to convert a String to a stream that way as your casting attempt so that it won't be stored in the Java memroy anymore. The source has to stay at the other side and it has to be retrieved byte by byte over the line. The only feasible approach would be to use an <iframe> whose src points to some HttpServlet which directly streams the data from the source to the response.

您最好的选择是将整个内容存储在数据库中,或者-如果其中不包含用户特定的数据,则将其存储在应用程序范围内,并在所有会话/请求中共享.

Your best bet is likely to store the whole thing in a database or --if it doesn't contain user specific data-- in the application scope and share it among all sessions/requests.

这篇关于流内容到JSF UI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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