Paul Spencer schrieb:
Simon Kitching wrote:
Paul Spencer schrieb:
I am dynamically adding child components to a form via the forms's
binding, <h:form .. binding="#{myBean.form}" />. My current
challenge is related to the valueChangeListner. Specifically the
listener is not called on the first change, but is called twice on
the second change. In addition the property being changed is updated
in the response as expected on both the first and second change.
1) Any ideas why I am seeing this behavior out of the listener?
Sorry, no idea.
2) Are their some issues/pointers/pitfalls I should be aware of when
dynamically adding child components to an existing bean?
(a) as for all bindings, don't hold onto the component reference for
more than request scope.
(b) you must explicitly set a (unique) id for each
dynamically-created component
If the ID is unique within the parent component, in this case a table,
is that sufficient?
The ids must be unique within the nearest ancestor component that
implements NamingContainer. The main NamingContainer components are
form, subview and dataTable. So in your case if you are adding child
components to a dataTable then that is fine; they only need to be unique
within the table.
Note that data-tables are rather unusual JSF components. If you are
adding components to a table you need to be more careful than adding
them to other non-iterating components. See the comments on this class
for some background info on jsf tables:
http://svn.apache.org/repos/asf/myfaces/core/trunk_1.2.x/api/src/main/java/javax/faces/component/UIData.java
(by the way, that info should be in the javadocs for UIData on the
myfaces website, but it looks like the javadocs on the website have not
been updated to reflect the latest release).
If not is their a utility the will return a unique id?
Nope. If you aren't able to assign meaningful names to them then the
usual way is to pick a unique prefix, eg "myprojname" then use a static
int (with appropriate locking) to generate a unique numeric suffix. The
names are then at least unique, if not helpful.
Regards,
Simon