简体   繁体   中英

JSF2-Behaviour of viewParam on viewscoped bean after postback

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM