绑定属性会导致在视图中找到重复的组件ID [英] Binding attribute causes duplicate component ID found in the view

查看:1185
本文介绍了绑定属性会导致在视图中找到重复的组件ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是JSF code:

Here is JSF code:

<h:inputText binding="#{bean.input}" />

和这里是绑定支持后台bean的一部分:

And here is a part of backing bean for binding support:

private HtmlInputText input;

public void setInput(HtmlInputText input) {
    this.input = input;
}

public HtmlInputText getInput() {
    return this.input;
}

当我在第一次打开网页一切正常,但是当我在第二次打开它(刷新或在另一个选项卡或任何其他方式打开同一个网址),我得到重复的ID错误。错误消息说,&LT; H:inputText的&GT; 没有唯一的ID。这里是长的错误消息的一部分:

When I open page at first time everything works fine but when I open it at second time (refresh or open the same url in another tab or any other way) I get duplicate ID error. Error message says that <h:inputText> has no unique ID. Here is a part of long error message:

java.lang.IllegalArgumentException: Component ID formId:inputId has already been found in the view
    +id: inputId type: javax.faces.component.html.HtmlInputText@cafebabe

问题发生后,我加入结合属性。如果我删除它,一切都将重新正常工作。如何正确使用结合属性?

The problem occured after I added binding attribute. If I remove it, everything will work fine again. How do I properly use binding attribute?

推荐答案

复制组件ID错误时可能出现的:

Duplicate component ID errors may occur when:


  • 相同的ID被用在不同的组件相同的 NamingContainer
  • 里面
  • 物理上不同的组件绑定到同一Bean的相同属性。

  • &LT; F:,子视图&GT; 是已在包括网页,而不是父页面中声明

  • 同样包括网页包括里面的相同 NamingContainer 多次。

  • 的组件是被动态,而无需显式ID分配的创建。

  • Same ID is used on different components inside the same NamingContainer.
  • Physically different components are bound to the same property of the same bean.
  • The <f:subview> is been declared in the include page instead of the parent page.
  • The same include page is included multiple times inside the same NamingContainer.
  • A component is been dynamically created without having an explicit ID assigned.

在这里,<一个href=\"http://docs.oracle.com/javaee/7/api/javax/faces/component/NamingContainer.html\"><$c$c>NamingContainer是除其他外&LT; H:形式&GT; &LT; H:dataTable的&GT; &LT; F:,子视图&GT;

在使用结合,你应该把它绑定到所使用的完全按相关组件上的每个请求的基础属性。您的具体情况表明,这种结合是由多个组件共享,也许在不同的请求。当您将组件绑定到后台bean的属性,则支持bean绝对不应该比请求范围更广的范围。另请参见 JSF 2.0 specitication 第3.1.5章(重点煤矿)

When using binding, you should bind it to a property which is used exclusively by the component in question on a per-request basis. Your specific case indicates that this binding is been shared by multiple components, perhaps across different requests. When you bind the component to a property of a backing bean, then the backing bean should absolutely not be in a broader scope than the request scope. See also JSF 2.0 specitication chapter 3.1.5 (emphasis mine):

...

组件绑定经常与那些通过Managed Bean的创建工具动态实例化的JavaBean一起使用(参见5.8.1节的VariableResolver和默认的VariableResolver)。 强烈建议应用程序开发人员把被指向按组件在请求范围结合前pressions管理的Bean。这是因为将其放置在会话或应用范围将需要线程安全中,由于UIComponent实例取决于单个线程的内部运行。也有对内存管理设置零件在绑定时潜在的负面影响会话范围。

Component bindings are often used in conjunction with JavaBeans that are dynamically instantiated via the Managed Bean Creation facility (see Section 5.8.1 "VariableResolver and the Default VariableResolver"). It is strongly recommend that application developers place managed beans that are pointed at by component binding expressions in "request" scope. This is because placing it in session or application scope would require thread-safety, since UIComponent instances depends on running inside of a single thread. There are also potentially negative impacts on memory management when placing a component binding in "session" scope.

See also:

  • How does the 'binding' attribute work in JSF? When and how should it be used?
  • How to use component binding in JSF right ? (request-scoped component in session scoped bean)
  • View scope: java.io.NotSerializableException: javax.faces.component.html.HtmlInputText
  • 这篇关于绑定属性会导致在视图中找到重复的组件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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