Serialization of ManagedProperty

我只是一个虾纸丫 提交于 2019-12-04 17:43:40

A solution is to avoid @ManagedProperty in @ViewScoped beans and evaluate the EL expression on demand. @ViewScoped beans will be stored in Session (and thus serialized) at the end of every request.

FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getApplication().evaluateExpressionGet(ctx, "#{sessionConfig}", SessionConfig.class)

Note that this may seriously affect perfromance if the expression has to be evaluated frequently.

A better aproach might be to provide custom serialization methods as described here: http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html This way the expression could be resolved automatically every time the bean is deserialized.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!