什么是JSF 2.0中的STATE_SAVING_METHOD参数 [英] What is STATE_SAVING_METHOD parameter in JSF 2.0

查看:92
本文介绍了什么是JSF 2.0中的STATE_SAVING_METHOD参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解web.xml中此行的功能

I am not able to understand what is the function of this line in web.xml

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

我已阅读到NetBeans的默认值为 client .我刚刚遇到一个问题,我的应用程序中有很多bean,并且<param-value>设置为客户端,所以我得到了

I have read that the NetBeans default is client. I've just faced an issue that I have many beans in my application, and the <param-value> was set to client, so I was getting

java.io.NotSerializableException

java.io.NotSerializableException

错误,尽管我的bean是可序列化的(即它们实现了Serializable接口.).我的豆子在 @ViewScope 中.但是,当我将其更改为服务器时,一切都会正常进行.为什么?使用客户端和服务器有什么区别?谁能在一个例子的帮助下向我解释.

error although my beans were Serializable (i.e. they implemented the Serializable interface.). My beans were in @ViewScope. But when I changed it to server, things are going to work. Why? What is the difference when I use client and server. Can anyone explain me with the help of an example.

谢谢

推荐答案

java.io.NotSerializableException

这种异常通常在根本原因中有一条消息,显示未实现Serializable的类的完全限定类名.您应该密切注意此消息,以了解它在谈论哪个类,然后使其相应地实现Serializable.

This kind of exception has usually a message in the root cause which shows the fully qualified class name of the class which doesn't implement Serializable. You should pay close attention to this message to learn about which class it is talking about and then let it implement Serializable accordingly.

通常,仅使 您的托管Bean类可序列化并不总是足够的.您还需要确保每个属性也是可序列化的.大多数标准类型,例如StringLong等,都已经实现了所有Serializable.但是,(自定义)复杂类型(例如嵌套bean,实体或EJB)也应分别可序列化.如果某些内容不能真正实现为Serializable,例如InputStream,则应该重新设计模型或将其设置为transient(并记住在反序列化后将成为null).

Often, making only your managed bean classes serializable is not always sufficient. You also need to ensure that each of its properties is also serializable. Most standard types like String, Long, etc implement all already Serializable. But (custom) complex types such as nested beans, entities or EJBs should each also be serializable. If something is not really implementable as Serializable, such as InputStream, then you should either redesign the model or make it transient (and keep in mind that it will be null after deserialization).

使用客户端和服务器时有什么区别

首先了解一些背景信息:

First some background information: Why JSF saves the state of UI components on server?

主要技术差异是client设置将整个视图状态存储为生成的HTML输出中javax.faces.ViewState隐藏输入字段的值,并且server设置将其与会话一起存储在会话中唯一ID,该ID又被引用为javax.faces.ViewState隐藏输入字段的值.

The main technical difference is that the client setting stores the entire view state as the value of the javax.faces.ViewState hidden input field in the generated HTML output and that the server setting stores it in the session along with an unique ID which is in turn referenced as the value of the javax.faces.ViewState hidden input field.

因此,设置为client会增加网络带宽使用率,但会减少服务器内存使用率,而将设置为server则相反.但是,设置为client具有其他功能优势:当会话过期或客户端打开太多视图时,它可以防止ViewExpiredException.

So, setting to client increases the network bandwidth usage but decreases the server memory usage and setting to server does the other way round. Setting to client has however an additional functional advantage: it prevents ViewExpiredExceptions when the session has expired or when the client opens too many views.

这篇关于什么是JSF 2.0中的STATE_SAVING_METHOD参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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