jsf - Binding attribute causes duplicate component ID found in the view -
here jsf code:
<h:inputtext binding="#{bean.input}" />
and here part of backing bean binding support:
private htmlinputtext input; public void setinput(htmlinputtext input) { this.input = input; } public htmlinputtext getinput() { return this.input; }
when open page @ first time works fine when open @ second time (refresh or open same url in tab or other way) duplicate id error. error message says <h:inputtext>
has no unique id. here part of long error message:
java.lang.illegalargumentexception: component id formid:inputid has been found in view +id: inputid type: javax.faces.component.html.htmlinputtext@cafebabe
the problem occured after added binding
attribute. if remove it, work fine again. how use binding
attribute?
duplicate component id errors may occur when:
- same id used on different components inside same
namingcontainer
. - physically different components bound same property of same bean.
- the
<f:subview>
been declared in include page instead of parent page. - the same include page included multiple times inside same
namingcontainer
. - a component been dynamically created without having explicit id assigned.
here, namingcontainer
among others <h:form>
, <h:datatable>
, <f:subview>
.
when using binding
, should bind property used exclusively component in question on per-request basis. specific case indicates binding been shared multiple components, perhaps across different requests. when bind component property of backing bean, backing bean should absolutely not in broader scope request scope. see jsf 2.0 specitication chapter 3.1.5 (emphasis mine):
3.1.5 component bindings
...
component bindings used in conjunction javabeans dynamically instantiated via managed bean creation facility (see section 5.8.1 “variableresolver , default variableresolver”). it recommend application developers place managed beans pointed @ component binding expressions in “request” scope. because placing in session or application scope require thread-safety, since uicomponent instances depends on running inside of single thread. there potentially negative impacts on memory management when placing component binding in “session” scope.
Comments
Post a Comment