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

查看:14
本文介绍了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 是可序列化的(即它们实现了可序列化接口.).我的 bean 在 @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).

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

首先是一些背景信息:为什么 JSF 将 UI 组件的状态保存在服务器上?

主要技术区别在于 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 有一个额外的功能优势:当会话过期或客户端打开太多视图时,它可以防止 ViewExpiredExceptions.

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天全站免登陆