回发后,在Viewscoped Bean上执行ViewParam的JSF2行为 [英] JSF2-Behaviour of viewParam on viewscoped bean after postback

查看:90
本文介绍了回发后,在Viewscoped Bean上执行ViewParam的JSF2行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过View监视的bean,它通过f:viewparam接收参数,并使用它们在模型中设置值.页面回发后,参数将从url中消失,但初始参数设置的模型值会以某种方式保留.

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.

这是保留参数的安全方法吗?还是应该在回发时重写url,以便保留初始参数的后续调用?

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?

推荐答案

以下是

[...]此标记导致将UIViewParameter作为元数据附加到当前视图.因为UIViewParameter扩展了UIInput,所以任何UIInput标签的所有属性和嵌套的子内容在此标签上也有效.

[...] 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.

这意味着<f:viewParam> value属性将使用request参数进行更新,并存储在viewstate中,并在再次提交页面时重新设置/重新验证.

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在这里有完整的故事: http://arjan-tijms.omnifaces.org/2011/07/stateless-vs-stateful-jsf-view.html

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

简而言之:使用@ViewScoped bean是完全可以的,但是如果您对该值使用昂贵的验证器/转换器,请注意,在该页面的每次回发中,它将再次被称为 .如果您想避免这种情况,请查看本文 BalusC中的>,其中解释了OmniFaces的无状态替代方法 o:viewParam .

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.

这篇关于回发后,在Viewscoped Bean上执行ViewParam的JSF2行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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