Binding sub-properties to child components

I'm writing a compound component based on UIPanel.

My component is passed a domain object with a number of properties, using a valuebinding.

In my component I create a number of child components using the standard ones, eg. HtmlInputText or checkbox, etc.

I want to bind these child components to properties of the domain object.

I've been trying to do this with the following code, which I include really only to illustrate what I'm trying to do. I don't think this is the way to do it because I really don't like hacking the expression.

ValueBinding vb=getValueBinding("element");

String s=vb.getExpressionString();

s=s.replace("}",".textValue}");

ValueBinding propVb=app.createValueBinding(s);

HtmlInputText hit=(HtmlInputText) app.createComponent(HtmlInputText.COMPONENT_TYPE);

hit.setValueBinding("value", propVb);

getChildren().add(hit);

To summarise, I want to build a component that can handle the editing UI for a domain object, with multiple child components in my custom component.

It's important that this is a custom component because I'm actually adding them to the view as a result of iterating a polymorphic list, with a different component for each object type in the list.

Hope this is clear and any help appreciated.

Alfie.

[1447 byte] By [akirkpatricka] at [2007-10-2 9:28:17]
# 1

The fact that my attempts do not work are related to the fact that my component is inside a forEach loop, and the value expression passed as my 'element' attribute is simply the var of the forEach, ie. "#{item}".

So the statement app.createValueBinding("#{item}") is not doing what I want since this binding doesn't exist in the application scope.

If I pass a property of a managed bean from facelets-context, it works after a fashion. But I still do not like the hacking of the expression.

Is there another way?

This post describes a similar problem but nobody posts a solution.

http://forum.java.sun.com/thread.jspa?forumID=427&threadID=495196

Thanks!

Alfie.

akirkpatricka at 2007-7-16 23:34:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I think I resolved this problem by creating a new subclass of ValueBinding which takes an original value binding and a property name.

It then proxies on getValue, setValue and other methods using the original value binding passed in and the property name (using commons-beanutils for help).

It's about 100 lines of code. This can't be the only way?! This seems like a fairly standard pattern to bind elements of a compound component to properties of a domain object, no?

Alfie.

akirkpatricka at 2007-7-16 23:34:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...