JSF2-Behaviour of viewParam on viewscoped bean after postback

本小妞迷上赌 提交于 2019-12-11 14:34:30

问题


I have a viewscoped bean wich receives parameters through f:viewparam and set values in the model using them. After a page postback, the parameters dissapear from the url but the model values setted by the initial params are retained somehow.

Is this a safe way of keeping parameters or should I rewrite the url on postback so it keeps the initial parameters subsequent calls?

How are the parameter retained? In the viewstate?


回答1:


Here's what the f:viewParam documentation says:

[...] this tag causes a UIViewParameter to be attached as metadata for the current view. Because UIViewParameter extends UIInput all of the attributes and nested child content for any UIInput tags are valid on this tag as well.

This means that the <f:viewParam> value attribute will be updated with the request parameter, stored in the viewstate and re-set/revalidated when you submit the page again.

Arjan Tijms has the full story here: http://arjan-tijms.omnifaces.org/2011/07/stateless-vs-stateful-jsf-view.html

In short: using a @ViewScoped bean is perfectly fine, but if you use an expensive validator/converter on that value be aware that it will be called again on each postback from that page. If you want to avoid that, have a look at this article from BalusC, which explains o:viewParam, OmniFaces' stateless alternative.



来源:https://stackoverflow.com/questions/21098126/jsf2-behaviour-of-viewparam-on-viewscoped-bean-after-postback

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