cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bart Molenkamp" <>
Subject Custom JXPath binding
Date Mon, 09 Aug 2004 07:30:58 GMT
Hi all,

I have  a little problem with JXPath bindings. Suppose I have a class
Person, and a class Project (persistent, via OJB). When I create a new
person (using a form of course), I can select on which project he/she
will be working, via a selection list. When the form is submitted, it
contains the ID of the project that has been selected. In a custom
binding I want to lookup the project object using the ID that is
submitted with the form, and then set that object as the project in the
person object that I've just created.

I thought this could be done using custom bindings. However, I see two
problems here:

1., line 83: the statement:
JXPathContext context =

throws a JXPath exception. That is because the project object in the
person object is null. What I need to do in my custom binding is
something like:
jxpc.setValue(this.xpath, theSelectedProject);

Maybe this is even a more generic problem. Try to bind a String this way
in where the String in the bean is null (throws same JXPath exception
because the String is null). So, is the getRelativeContext statement
needed there? Isn't it better to pass the xpath string along with the
context to the custom binding? This would solve my problem.

2. It might be useful for custom bindings to have access to a service
manager. This can be done fairly easy. The CustomJXPathBindingBuilder
has access to the service manager in it's Assistant. It could pass it on
in the CustomJXPathBinding instances that it creates. These instances
could pass it on to custom bindings that implement the Serviceable
interface (e.g. using the LifecycleHelper class). This would have no
effect on existing bindings (I think).

I think my problem is a more generic problem (binding between ID in form
-> real object in bean), and it would be nice if this could be done
inside the binding framework.


View raw message