You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Bart Molenkamp <b....@bizzdesign.nl> on 2004/08/09 09:30:58 UTC

Custom JXPath binding

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. CustomJXPathBinding.java, line 83: the statement:
JXPathContext context =
jxpc.getRelativeContext(jxpc.getPointer(this.xpath));

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.

Thanks,
Bart.

Re: Custom JXPath binding

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Bart Molenkamp wrote:
> 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. CustomJXPathBinding.java, line 83: the statement:
> JXPathContext context =
> jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
> 
> 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.
I think this is a very good enhancement - I have the same problems with 
my hibernate entities. Had to implement dummy java classes for that 
"binding"..

I would recommend you to provide a patch - that is the fastest way to 
incorporate your proposals. I am not a commiter though so I cannot 
guarantee you that it will be commited.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl