You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alex Romayev <ro...@yahoo.com> on 2005/02/27 16:53:04 UTC
[cforms] Partial Binding
I have a collection of objects which I want to edit using a repeater.
The object which the repeater binds to has about 15 fields out of which
I only need to display 2 and edit only one. The problem is that if I
only specify bindings for the 2 field I need, the rest of the 13 would
all get cleared when the form is saved back to the bean.
Is there a way to avoid specifying bindings for all the fields and not
have them overwritten during the save?
Thanks,
-Alex
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
On Feb 28, 2005, at 2:16 AM, Jorg Heymans wrote:
>
>
> Alex Romayev wrote:
>> On Feb 27, 2005, at 2:22 PM, Jorg Heymans wrote:
>>> There are tools out there that generate classes from datamodels (eg
>>> Middlegen) through a templating engine. You could create your own
>>> templates that spit out CForms tags/Betwixt mappings instead of the
>>> usual DAO java code.
>> I like the tool, thank for the tip.
>> I'm not sure what you mean by splitting out CForms tags/Betwixt
>> mappings. Do you mean auto-generating form defition/binding and
>> betwixt mappings from the database definition?
>
> that's what i was implying yes. Unless ofcourse you've customized them
> so much that they don't resemble the database model anymore...
>
>> One way I was thinking sorting out not having to create form beans
>> was the following:
>> 1. On load - bind to the actual business beans
>> 2. On save - bind to XML, then pass the XML to an object that would
>> set the appropriate fields on the actual beans and save them to the
>> database. Basically the same as passing a DAO, but not having to
>> actually create one.
>
> You can use custom javascript bindings as Sylvain already said. And
> apparently by looking at his post you can bind to an existing bean
> without overwriting some of its attribute values. Keep us posted !
That's what it seems like to me as well, but I don't really understand.
Sylvain, could you clarify?
Thanks,
-Alex
>
>
> Regards
> Jorg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
On Feb 28, 2005, at 2:16 AM, Jorg Heymans wrote:
> You can use custom javascript bindings as Sylvain already said. And
> apparently by looking at his post you can bind to an existing bean
> without overwriting some of its attribute values. Keep us posted !
I failed to use the fd:identity tag, which was why I was getting new
objects as opposed to the old ones being bound to by the repeater. I
feel really silly now :-(
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Jorg Heymans <jh...@domek.be>.
Alex Romayev wrote:
>
> On Feb 27, 2005, at 2:22 PM, Jorg Heymans wrote:
>
>> There are tools out there that generate classes from datamodels (eg
>> Middlegen) through a templating engine. You could create your own
>> templates that spit out CForms tags/Betwixt mappings instead of the
>> usual DAO java code.
>
>
> I like the tool, thank for the tip.
>
> I'm not sure what you mean by splitting out CForms tags/Betwixt
> mappings. Do you mean auto-generating form defition/binding and betwixt
> mappings from the database definition?
that's what i was implying yes. Unless ofcourse you've customized them
so much that they don't resemble the database model anymore...
>
> One way I was thinking sorting out not having to create form beans was
> the following:
>
> 1. On load - bind to the actual business beans
> 2. On save - bind to XML, then pass the XML to an object that would set
> the appropriate fields on the actual beans and save them to the
> database. Basically the same as passing a DAO, but not having to
> actually create one.
You can use custom javascript bindings as Sylvain already said. And
apparently by looking at his post you can bind to an existing bean
without overwriting some of its attribute values. Keep us posted !
Regards
Jorg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
On Feb 27, 2005, at 2:22 PM, Jorg Heymans wrote:
> There are tools out there that generate classes from datamodels (eg
> Middlegen) through a templating engine. You could create your own
> templates that spit out CForms tags/Betwixt mappings instead of the
> usual DAO java code.
I like the tool, thank for the tip.
I'm not sure what you mean by splitting out CForms tags/Betwixt
mappings. Do you mean auto-generating form defition/binding and
betwixt mappings from the database definition?
One way I was thinking sorting out not having to create form beans was
the following:
1. On load - bind to the actual business beans
2. On save - bind to XML, then pass the XML to an object that would set
the appropriate fields on the actual beans and save them to the
database. Basically the same as passing a DAO, but not having to
actually create one.
-Alex
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Jorg Heymans <jh...@domek.be>.
Alex Romayev wrote:
> I'm sort of split on this one. Would be interested in hearing other
> people's opinions/ideas.
>
> There are pros and cons in doing this separation. Technically if in a
> typical design you would almost need to have 3 layers of beans:
>
> 1. Form Beans - used to save forms to.
> 2. Business Beans.
> 3. Data Beans -used for data persistence by say OJB or in my case
> Hibernate.
2. and 3. might not always be separate but yes these 3 layers are
potentially always involved.
> HOWEVER:
>
> If I want to add an attribute I would need to change:
I'm assuming you mean an attribute that needs persisting.
> 1. Database table
can't get around this
> 2. Object/relational mapping
yes but can be autogenerated from 1.
> 3. Data bean
yes but can be autogenerated from 2.
> 4. Business bean
yes
> 5. Form bean
> 6. Form definition
> 7. Form binding
> 8. Potentially a betwixt mapping if you use the bean to stream out XML
> for you presentation
> 9. Various mapping methods, such as Form Bean to Business bean, etc
yes x5
> Bloody nightmare!!!
There are tools out there that generate classes from datamodels (eg
Middlegen) through a templating engine. You could create your own
templates that spit out CForms tags/Betwixt mappings instead of the
usual DAO java code.
Interesting discussion,
Jorg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
On Feb 27, 2005, at 5:59 PM, Sylvain Wallez wrote:
> Alex Romayev wrote:
>
>> I'm sort of split on this one. Would be interested in hearing other
>> people's opinions/ideas.
>>
>> There are pros and cons in doing this separation. Technically if in
>> a typical design you would almost need to have 3 layers of beans:
>>
>> 1. Form Beans - used to save forms to.
>> 2. Business Beans.
>> 3. Data Beans -used for data persistence by say OJB or in my case
>> Hibernate.
>>
>> The Form Beans are useful, as it is frequently not possible to have
>> the business object model available during binding. For example,
>> it's a complex model and you are using the "Builder" pattern to
>> properly create all the beans and their relationships or only part of
>> the model comes from the user input and the rest from querying other
>> systems, e.g. LDAP.
>
>
> Ok, but for simple cases, you really don't need a form bean. CForms
> has its own data model used to shield the application data from
> request parameters. If you need partial binding on a repeater, have a
> look at the <fb:repeater> binding that can bind to existing objects
> without recreating them from scratch.
Hmm... this takes me back to my original question. I have a list of
objects that I need to edit. Two problems:
1. I only have 1 property that I need to edit, however, it seems that I
need to specify read-only ("load") bindings for all other multiple
properties, so that they don't get overwritten. Is there a way to
instruct the repeater-binding to not overwrite all elements, but the
ones I need, for example:
<fb:repeater id="items"
parent-path="."
row-path="item">
<fb:on-bind>
<!-- This is the attribute I want to edit -->
<fb:value id="editable" path="editable"/>
<!-- Do not overwrite all other attributes -->
<fb:value id="*" path="*" direction="load"/>
</fb:on-bind>
...
2. It appears that it is not possible to specify addmethod="add", where
add is the add(Object o) of a Collection in "fb:insert-bean" when the
real object being added to the list is of a different type, i.e.
add(MyObject). This means that I still need to implement a wrapper
bean with the add(MyObject) method.
In summary, all I'm trying to do is have a form that allows to edit one
field in each item in a list and in order to achieve this (unless I'm
missing something) I have to implement a wrapper object and a binding
that lists all of the other completely unused attributes... talk about
keeping it simple ;-)
>
> And for more complex cases, you can also use the <fb:javascript>
> binding where you do anything you want to load/save the form. LDAP
> could go there (or in a class called there).
>
>> Business Beans provide a stronger model. For example, you might not
>> want to have getPassword() method on your User bean and have
>> isValidPassword(String password) instead or not provide some of the
>> setter methods to ensure immutability of some of your fields.
>
>
> The isValidPassword() isn't IMO a binding concern, but a validation
> problem.
True, but exposing getPassword() is a security concern ;-)
>
>> Hence, there is a need to have Data Beans, where each property has a
>> gettter and a setter and this way can be mapped to database tables.
>>
>> HOWEVER:
>>
>> If I want to add an attribute I would need to change:
>> 1. Database table
>> 2. Object/relational mapping
>> 3. Data bean
>> 4. Business bean
>> 5. Form bean
>> 6. Form definition
>> 7. Form binding
>> 8. Potentially a betwixt mapping if you use the bean to stream out
>> XML for you presentation
>> 9. Various mapping methods, such as Form Bean to Business bean, etc
>>
>> Bloody nightmare!!!
>>
>>
>> Thoughts?
>
>
> Yes: forget about Form bean, and bind the form to Business bean or
> Data bean if there's really a need for it.
>
> Sylvain
>
> --
> Sylvain Wallez Anyware Technologies
> http://www.apache.org/~sylvain http://www.anyware-tech.com
> { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Sylvain Wallez <sy...@apache.org>.
Alex Romayev wrote:
> I'm sort of split on this one. Would be interested in hearing other
> people's opinions/ideas.
>
> There are pros and cons in doing this separation. Technically if in a
> typical design you would almost need to have 3 layers of beans:
>
> 1. Form Beans - used to save forms to.
> 2. Business Beans.
> 3. Data Beans -used for data persistence by say OJB or in my case
> Hibernate.
>
> The Form Beans are useful, as it is frequently not possible to have
> the business object model available during binding. For example, it's
> a complex model and you are using the "Builder" pattern to properly
> create all the beans and their relationships or only part of the model
> comes from the user input and the rest from querying other systems,
> e.g. LDAP.
Ok, but for simple cases, you really don't need a form bean. CForms has
its own data model used to shield the application data from request
parameters. If you need partial binding on a repeater, have a look at
the <fb:repeater> binding that can bind to existing objects without
recreating them from scratch.
And for more complex cases, you can also use the <fb:javascript> binding
where you do anything you want to load/save the form. LDAP could go
there (or in a class called there).
> Business Beans provide a stronger model. For example, you might not
> want to have getPassword() method on your User bean and have
> isValidPassword(String password) instead or not provide some of the
> setter methods to ensure immutability of some of your fields.
The isValidPassword() isn't IMO a binding concern, but a validation problem.
> Hence, there is a need to have Data Beans, where each property has a
> gettter and a setter and this way can be mapped to database tables.
>
> HOWEVER:
>
> If I want to add an attribute I would need to change:
> 1. Database table
> 2. Object/relational mapping
> 3. Data bean
> 4. Business bean
> 5. Form bean
> 6. Form definition
> 7. Form binding
> 8. Potentially a betwixt mapping if you use the bean to stream out XML
> for you presentation
> 9. Various mapping methods, such as Form Bean to Business bean, etc
>
> Bloody nightmare!!!
>
>
> Thoughts?
Yes: forget about Form bean, and bind the form to Business bean or Data
bean if there's really a need for it.
Sylvain
--
Sylvain Wallez Anyware Technologies
http://www.apache.org/~sylvain http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
I'm sort of split on this one. Would be interested in hearing other
people's opinions/ideas.
There are pros and cons in doing this separation. Technically if in a
typical design you would almost need to have 3 layers of beans:
1. Form Beans - used to save forms to.
2. Business Beans.
3. Data Beans -used for data persistence by say OJB or in my case
Hibernate.
The Form Beans are useful, as it is frequently not possible to have the
business object model available during binding. For example, it's a
complex model and you are using the "Builder" pattern to properly
create all the beans and their relationships or only part of the model
comes from the user input and the rest from querying other systems,
e.g. LDAP.
Business Beans provide a stronger model. For example, you might not
want to have getPassword() method on your User bean and have
isValidPassword(String password) instead or not provide some of the
setter methods to ensure immutability of some of your fields.
Hence, there is a need to have Data Beans, where each property has a
gettter and a setter and this way can be mapped to database tables.
HOWEVER:
If I want to add an attribute I would need to change:
1. Database table
2. Object/relational mapping
3. Data bean
4. Business bean
5. Form bean
6. Form definition
7. Form binding
8. Potentially a betwixt mapping if you use the bean to stream out XML
for you presentation
9. Various mapping methods, such as Form Bean to Business bean, etc
Bloody nightmare!!!
Thoughts?
-Alex
On Feb 27, 2005, at 12:58 PM, Jorg Heymans wrote:
>
>
> Alex Romayev wrote:
>> If I understand you correctly, then I'd need to look through the
>> "form" beans, match them with the actual beans and the the values.
>> Sort of defeats the purpose of using the binding in the first place?
>
> Why ? I find it good practice to have form beans as an extra layer
> between the real "business" beans and the user.
>
>
> Jorg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Jorg Heymans <jh...@domek.be>.
Alex Romayev wrote:
> If I understand you correctly, then I'd need to look through the "form"
> beans, match them with the actual beans and the the values. Sort of
> defeats the purpose of using the binding in the first place?
>
Why ? I find it good practice to have form beans as an extra layer
between the real "business" beans and the user.
Jorg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
Ok, I see what you're saying. Thanks.
On Feb 27, 2005, at 12:18 PM, Johnson wrote:
> pls see ojb sample. employee.js.
> use bean to store data
> use dao to copy data between beans
>
> johnson
>
> ----- Original Message ----- From: "Alex Romayev" <ro...@yahoo.com>
> To: <us...@cocoon.apache.org>
> Sent: Monday, February 28, 2005 12:55 AM
> Subject: Re: [cforms] Partial Binding
>
>
>> If I understand you correctly, then I'd need to look through the
>> "form" beans, match them with the actual beans and the the values.
>> Sort of defeats the purpose of using the binding in the first place?
>> On Feb 27, 2005, at 11:41 AM, Johnson wrote:
>>> create two beans,one for form,one for backup old value
>>>
>>> johnson
>>>
>>> ----- Original Message ----- From: "Alex Romayev" <ro...@yahoo.com>
>>> To: <us...@cocoon.apache.org>
>>> Sent: Sunday, February 27, 2005 11:53 PM
>>> Subject: [cforms] Partial Binding
>>>
>>>
>>>> I have a collection of objects which I want to edit using a
>>>> repeater. The object which the repeater binds to has about 15
>>>> fields out of which I only need to display 2 and edit only one.
>>>> The problem is that if I only specify bindings for the 2 field I
>>>> need, the rest of the 13 would all get cleared when the form is
>>>> saved back to the bean.
>>>> Is there a way to avoid specifying bindings for all the fields and
>>>> not have them overwritten during the save?
>>>> Thanks,
>>>> -Alex
>>>> --------------------------------------------------------------------
>>>> -
>>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Johnson <jo...@soho.club.tw>.
pls see ojb sample. employee.js.
use bean to store data
use dao to copy data between beans
johnson
----- Original Message -----
From: "Alex Romayev" <ro...@yahoo.com>
To: <us...@cocoon.apache.org>
Sent: Monday, February 28, 2005 12:55 AM
Subject: Re: [cforms] Partial Binding
> If I understand you correctly, then I'd need to look through the "form"
> beans, match them with the actual beans and the the values. Sort of
> defeats the purpose of using the binding in the first place?
>
> On Feb 27, 2005, at 11:41 AM, Johnson wrote:
>
>> create two beans,one for form,one for backup old value
>>
>> johnson
>>
>> ----- Original Message ----- From: "Alex Romayev" <ro...@yahoo.com>
>> To: <us...@cocoon.apache.org>
>> Sent: Sunday, February 27, 2005 11:53 PM
>> Subject: [cforms] Partial Binding
>>
>>
>>> I have a collection of objects which I want to edit using a
>>> repeater. The object which the repeater binds to has about 15 fields
>>> out of which I only need to display 2 and edit only one. The problem
>>> is that if I only specify bindings for the 2 field I need, the rest
>>> of the 13 would all get cleared when the form is saved back to the
>>> bean.
>>> Is there a way to avoid specifying bindings for all the fields and
>>> not have them overwritten during the save?
>>> Thanks,
>>> -Alex
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Alex Romayev <ro...@yahoo.com>.
If I understand you correctly, then I'd need to look through the "form"
beans, match them with the actual beans and the the values. Sort of
defeats the purpose of using the binding in the first place?
On Feb 27, 2005, at 11:41 AM, Johnson wrote:
> create two beans,one for form,one for backup old value
>
> johnson
>
> ----- Original Message ----- From: "Alex Romayev" <ro...@yahoo.com>
> To: <us...@cocoon.apache.org>
> Sent: Sunday, February 27, 2005 11:53 PM
> Subject: [cforms] Partial Binding
>
>
>> I have a collection of objects which I want to edit using a
>> repeater. The object which the repeater binds to has about 15 fields
>> out of which I only need to display 2 and edit only one. The problem
>> is that if I only specify bindings for the 2 field I need, the rest
>> of the 13 would all get cleared when the form is saved back to the
>> bean.
>> Is there a way to avoid specifying bindings for all the fields and
>> not have them overwritten during the save?
>> Thanks,
>> -Alex
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org
Re: [cforms] Partial Binding
Posted by Johnson <jo...@soho.club.tw>.
create two beans,one for form,one for backup old value
johnson
----- Original Message -----
From: "Alex Romayev" <ro...@yahoo.com>
To: <us...@cocoon.apache.org>
Sent: Sunday, February 27, 2005 11:53 PM
Subject: [cforms] Partial Binding
> I have a collection of objects which I want to edit using a repeater.
> The object which the repeater binds to has about 15 fields out of which
> I only need to display 2 and edit only one. The problem is that if I
> only specify bindings for the 2 field I need, the rest of the 13 would
> all get cleared when the form is saved back to the bean.
>
> Is there a way to avoid specifying bindings for all the fields and not
> have them overwritten during the save?
>
>
> Thanks,
> -Alex
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org