了解JSF组件类的生存期 [英] Understanding JSF components class lifetime

查看:116
本文介绍了了解JSF组件类的生存期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

组件的寿命是多少?遍历UIInput源我已经注意到,有一个名为value的本地字段,它实质上是该组件的值.我还注意到,在处理所有转换和验证之后,我们将新值与组件的旧值进行比较,如果它们是不同的,则比较fire valueChange事件.实际上,这是接管排队事件的代码:

What's the component's lifetime? Traversing the UIInput sources I've noticed that there's local field called value which is essentailly the value of the component. I've also noticed that after processing all convertion and validation we compare a new value with an old value of the component and if they're different fire valueChange event. Actually, here's the piece of code taking over the quing events:

if (isValid()) {
     Object previous = getValue();
     setValue(newValue);
     setSubmittedValue(null);
     if (compareValues(previous, newValue)) {
         queueEvent(new ValueChangeEvent(this, previous, newValue)); // <-----
     }
}

但是,如果组件在任何请求后被杀死,那么我们在发送请求时就会得到ValueChangeEvent.因此,我假设组件的生存期与组件绑定到属性的Bean的生存期相同.但是我找不到任何文件保证...

But if the component were killed after any request, we would simply get ValueChangeEvent eny time we send a request. So, I presume the component's lifetime is the same as the bean's lifetime which the component bound to the property to. But I couldn't find any documental assurance...

推荐答案

组件实例在请求范围内.仅委托给 UIComponent#getStateHelper() 在视图范围内. IE.它们以JSF视图状态保存.其中包括 ValueHolder#getLocalValue() (getValue()委托给该对象).

Component instances are request scoped. Only component properties which are delegated to UIComponent#getStateHelper() are view scoped. I.e. they are saved in the JSF view state. This covers among others the ValueHolder#getLocalValue() which the getValue() is delegating to.

@Override
public Object getValue() {
    return isLocalValueSet() ? getLocalValue() : super.getValue();
}

仅在无状态视图(即带有<f:view transient="true">的页面)上,您描述的行为我们确实会在发送请求时得到ValueChangeEvent,".

Only on stateless views, i.e. pages with <f:view transient="true">, the behavior as you described "we would simply get ValueChangeEvent eny time we send a request" will indeed happen.

  • How does the 'binding' attribute work in JSF? When and how should it be used?
  • How to save state when extending UIComponentBase
  • What is the usefulness of statelessness in JSF?

这篇关于了解JSF组件类的生存期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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