You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <ug...@apache.org> on 2005/07/29 16:04:10 UTC

[CForms] Creating an intermediate object in binding

Let's assume I have a Person class:

public class Person {
   public String getFirstname();
   public String getLastname();
   public Address getAddress();
   ...
}

and an Address class:

public class Address {
   public String getStreet();
   public String getTown();
   ...
}

I am building a form interface for editing a Person, with this binding:

<fb:value id="street" path="address/street"/>

Now, when trying to save the form, JXPath will do a  
jxpathContext.createPathAndSetValue which will fail because  
person.getAddress() is null and the JXPath context doesn't know how to  
create an Address.

I could work around this problem by making sure person.address is not  
null before loading it into the form, but I don't like this solution. A  
better option, maybe, would be setting a factory on the context, like  
is shown here:  
http://jakarta.apache.org/commons/jxpath/users- 
guide.html#Creating%20Objects

My problem is: where do I set this factory in CForms, assuming this is  
possible at all?

	Thanks in Advance,

		Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/


Re: [CForms] Creating an intermediate object in binding

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 29/lug/05, alle 16:34, Sylvain Wallez ha scritto:

> The solution would be to allow each JXPath binding to have its own 
> factory class. This can be easily implented by adding support for a 
> "factory" attribute in JXPathBindingBuilderBase.

I just committed (BRANCH_2_1_X only ATM) a fix that allows you to add a 
"factory" attribute to fb:context elements. We could probably do the 
same for fb:value elements but since intermediate objects are usually 
meant to be containers for other objects (the typical "address" case), 
having to group them within an fb:context is probably good practice 
anyway and not too much of a requirement.

Anyway, I just wanted to ask someone to cross-check my implementation, 
since I'm not familiar enough with the binding framework to spot 
obvious deficiencies.

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/


Re: [CForms] Creating an intermediate object in binding

Posted by Sylvain Wallez <sy...@apache.org>.
Ugo Cei wrote:

> Let's assume I have a Person class:
>
> public class Person {
>   public String getFirstname();
>   public String getLastname();
>   public Address getAddress();
>   ...
> }
>
> and an Address class:
>
> public class Address {
>   public String getStreet();
>   public String getTown();
>   ...
> }
>
> I am building a form interface for editing a Person, with this binding:
>
> <fb:value id="street" path="address/street"/>
>
> Now, when trying to save the form, JXPath will do a  
> jxpathContext.createPathAndSetValue which will fail because  
> person.getAddress() is null and the JXPath context doesn't know how 
> to  create an Address.
>
> I could work around this problem by making sure person.address is not  
> null before loading it into the form, but I don't like this solution. 
> A  better option, maybe, would be setting a factory on the context, 
> like  is shown here:  http://jakarta.apache.org/commons/jxpath/users- 
> guide.html#Creating%20Objects
>
> My problem is: where do I set this factory in CForms, assuming this 
> is  possible at all?


Currently, it is not possible.

The solution would be to allow each JXPath binding to have its own 
factory class. This can be easily implented by adding support for a 
"factory" attribute in JXPathBindingBuilderBase.

Sylvain

-- 
Sylvain Wallez                        Anyware Technologies
http://people.apache.org/~sylvain     http://www.anyware-tech.com
Apache Software Foundation Member     Research & Technology Director


Re: [CForms] Creating an intermediate object in binding

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 30/lug/05, alle 05:25, Antonio Gallardo ha scritto:

> Do you tried the 2.1.8-dev branch? I remember to have a similar 
> problem few months ago, but I am not sure if this is exactly what are 
> you looking for.

I am using 2.1.8-dev right now.

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/


Re: [CForms] Creating an intermediate object in binding

Posted by Antonio Gallardo <ag...@agssa.net>.
Hi Ugo:

Do you tried the 2.1.8-dev branch? I remember to have a similar problem 
few months ago, but I am not sure if this is exactly what are you 
looking for.

Best Regards,

Antonio Gallardo.

Ugo Cei wrote:

> Let's assume I have a Person class:
>
> public class Person {
>   public String getFirstname();
>   public String getLastname();
>   public Address getAddress();
>   ...
> }
>
> and an Address class:
>
> public class Address {
>   public String getStreet();
>   public String getTown();
>   ...
> }
>
> I am building a form interface for editing a Person, with this binding:
>
> <fb:value id="street" path="address/street"/>
>
> Now, when trying to save the form, JXPath will do a  
> jxpathContext.createPathAndSetValue which will fail because  
> person.getAddress() is null and the JXPath context doesn't know how 
> to  create an Address.
>
> I could work around this problem by making sure person.address is not  
> null before loading it into the form, but I don't like this solution. 
> A  better option, maybe, would be setting a factory on the context, 
> like  is shown here:  http://jakarta.apache.org/commons/jxpath/users- 
> guide.html#Creating%20Objects
>
> My problem is: where do I set this factory in CForms, assuming this 
> is  possible at all?
>
>     Thanks in Advance,
>
>         Ugo
>


Re: [CForms] Creating an intermediate object in binding

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 31/lug/05, alle 14:01, Leszek Gawron ha scritto:

>> I have defined a custom type and convertor for that. The convertor is 
>> actually managed by Spring and populated with a DAO and the 
>> convertor's factory returns the Spring-managed instance instead of 
>> creating a new one.
> The convertor itself is spring manager or just the dao it holds?

Both.
>
> Do I get it right that you need to implement a separate:
>
> - dao
> - convertor
> - convertor builder
>
> for every domain object in your model?

Not really. I do it only for those types that are reused across many 
forms and therefore warrant defining a datatype and convertor. At the 
moment, we have developed datatypes for a bunch of "geographical" 
objects like Town, Province, Country, that are used in all the forms 
where you have to input an address. And we have a single "GeoDAO" class 
for all entities of this kind.

In general, I would do this for every "datatype" that is implemented as 
a look-up-table (key => value) in the database and is reused in more 
than a couple of forms, or across more than one different project.

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/


Re: [CForms] Creating an intermediate object in binding

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Ugo Cei wrote:
> Il giorno 29/lug/05, alle 16:34, Leszek Gawron ha scritto:
> 
>> There is one more thing that is awkward with binding: imagine you have 
>> a  OR model with many-to-many relationship. Cforms will allow you to 
>> create  a form with a selection list to define those relationships. 
>> But wait: what you get are the ids of entities not entities themselves.
>>
>> Binding API does not give you access to service manager so you won't 
>> be able to lookup some dao and load the entity by its id.
> 
> 
> I have defined a custom type and convertor for that. The convertor is 
> actually managed by Spring and populated with a DAO and the convertor's 
> factory returns the Spring-managed instance instead of creating a new one.
The convertor itself is spring manager or just the dao it holds?

Do I get it right that you need to implement a separate:

- dao
- convertor
- convertor builder

for every domain object in your model?

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65

Re: [CForms] Creating an intermediate object in binding

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 29/lug/05, alle 16:34, Leszek Gawron ha scritto:

> There is one more thing that is awkward with binding: imagine you have 
> a  OR model with many-to-many relationship. Cforms will allow you to 
> create  a form with a selection list to define those relationships. 
> But wait: what you get are the ids of entities not entities 
> themselves.
>
> Binding API does not give you access to service manager so you won't 
> be able to lookup some dao and load the entity by its id.

I have defined a custom type and convertor for that. The convertor is 
actually managed by Spring and populated with a DAO and the convertor's 
factory returns the Spring-managed instance instead of creating a new 
one.

But this does not help me with my problem.

	Ugo

-- 
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/


Re: [CForms] Creating an intermediate object in binding

Posted by Leszek Gawron <lg...@mobilebox.pl>.
Ugo Cei wrote:
> Let's assume I have a Person class:
> 
> public class Person {
>   public String getFirstname();
>   public String getLastname();
>   public Address getAddress();
>   ...
> }
> 
> and an Address class:
> 
> public class Address {
>   public String getStreet();
>   public String getTown();
>   ...
> }
> 
> I am building a form interface for editing a Person, with this binding:
> 
> <fb:value id="street" path="address/street"/>
> 
> Now, when trying to save the form, JXPath will do a  
> jxpathContext.createPathAndSetValue which will fail because  
> person.getAddress() is null and the JXPath context doesn't know how to  
> create an Address.
> 
> I could work around this problem by making sure person.address is not  
> null before loading it into the form, but I don't like this solution. A  
> better option, maybe, would be setting a factory on the context, like  
> is shown here:  http://jakarta.apache.org/commons/jxpath/users- 
> guide.html#Creating%20Objects
> 
> My problem is: where do I set this factory in CForms, assuming this is  
> possible at all?
I do not think this is possible in current implementation (I am not sure 
though). Still the approach implemented by JXPath does not scale well - 
  you would have to duplicate all info about relationships in your OR 
model.

There is one more thing that is awkward with binding: imagine you have a 
  OR model with many-to-many relationship. Cforms will allow you to 
create  a form with a selection list to define those relationships. But 
wait: what you get are the ids of entities not entities themselves.

Binding API does not give you access to service manager so you won't be 
able to lookup some dao and load the entity by its id.

-- 
Leszek Gawron                                      lgawron@mobilebox.pl
IT Manager                                         MobileBox sp. z o.o.
+48 (61) 855 06 67                              http://www.mobilebox.pl
mobile: +48 (501) 720 812                       fax: +48 (61) 853 29 65