Community
Participate
Working Groups
I propose to add a new constructor to NestedProperty for writing : new NestedProperty(myObject, "member.lastName") What do you think about ? public NestedProperty(Object object, String propertiesPath) throws BindException { try { if (propertiesPath.indexOf('.') != -1) { List<String> l_properties = new ArrayList<String>(); List<Class> l_classes = new ArrayList<Class>(); StringTokenizer l_tokenizer = new StringTokenizer(propertiesPath, "."); Class l_class = object.getClass(); while (l_tokenizer.hasMoreTokens()) { String l_token = l_tokenizer.nextToken(); l_properties.add(l_token); l_class = getType(l_class, l_token); l_classes.add(l_class); } String[] l_propertiesParam = new String[l_properties.size()]; l_properties.toArray(l_propertiesParam); Class[] l_classesParam = new Class[l_classes.size()]; l_classes.toArray(l_classesParam); return new NestedProperty(object, l_propertiesParam, l_classesParam); } else { return new Property(object, propertiesPath); } } catch (IntrospectionException e) { throw new BindException(e.getMessage()); } }
I believe this is for databinding - we have several Property classes. If it isn't please punt back to me.
Thanks for the suggestion. However, for now, we are shying away from defining our own string-based language for object paths. Feel free to use this code in your application if your property identifiers are strings, it's just that we won't add this to the framework at this point. Closing as LATER.
The 3.3M5 API includes most of what's needed to solve this. This snippet should get you the rest of the way. I'm using Java 5 regex support, but you could trivially re-implement the call to split() if you need to run on older JVMs. import static org.eclipse.core.databinding.beans.BeansObservables.*; public static IObservableValue observeNestedValue(Object bean, String property) { Realm realm = Realm.getDefault(); // JSTL EL uses a simple period-delimited list of property names String[] parts = property.split("\\."); // Start out with a simple property IObservableValue lastPart = observeValue(realm, bean, parts[0]); for (int i = 1; i < parts.length; i++) { String part = parts[i]; // Each additional part should listen to changes on both host and value lastPart = observeDetailValue(realm, lastPart, part, null); } return lastPart; }
Note: Tom Schindl posted a similar solution in bug #195222
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.