You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Philipp Rech <re...@iuw.fh-darmstadt.de> on 2004/12/13 12:34:24 UTC

Usage of "form.createBinding" compared with "form.load"

Hello Cocooners,

[Cocoon Version 2.1.6]

i have a question about the binding-framework. right know i use it like this:

---------Sitemap---------------
<map:match pattern="binding">
   <map:call function="handleForm">
      <map:parameter name="function" value="myBinding"/>
      <map:parameter name="form-definition" value="form.xml"/>
      <map:parameter name="bindingURI" value="binding.xml"/>
   </map:call>
</map:match>
-------------------------------



---------Flowscript ------------
function myBinding(form) {
   var bean = new Packages.foo.bar.cocoonBean();
   form.load(bean);
   form.showForm("registration-display-pipeline");
   form.save(bean);
   cocoon.sendPage("registration-success-pipeline", {"model": bean});
}

-------------------------------

that works fine so far!
*****My question:*************

how does " form.createBinding("my_binding.xml"); " 
(which i found in the flowscript of the samples folder) work? Is it 
diffrent/better than my version? If i use form.createBinding
do i still have to use the same sitemap as above?

I am asking all this because I have a longer Flowscript that
switches (switch/case block) over serval forms and I wonder how 
to implement a flowscript and binding with ore than one form.

Thank you very much for your help!
phil

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


[solved] multiple forms (was: Usage of "form.createBinding" compared with"form.load")

Posted by Philipp Rech <re...@iuw.fh-darmstadt.de>.
> The default handles only one form on a page, not many forms. CForms is 
> not even really multiple-forms-aware, but taking care about some things 
> should make it possible.
> 

thank you! it works now... i call handleForm and pass several bindings and form
definitions (from the sitemap) to it. In case you guys are interested here
is how i've done it:

In the flowscript i reverence them again (!) like:

var form1 = new Form("cform-definitions/form1.xml");
form1.createBinding("binding/binding1.xml"); 
var form2 = new Form("cform-definitions/form2.xml");
form2.createBinding("binding/binding2.xml"); 

it is important to call the function that is defined in the
sitmap without any parameters: function myBinding()
I decide which form to show via a switch/case statment using a 
variable from a request parameter....

works fine also with hibernate.... beautiful!
thanks Joerg,

phil

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


multiple forms (was: Usage of "form.createBinding" compared with "form.load")

Posted by Joerg Heinicke <jo...@gmx.de>.
On 13.12.2004 14:29, Philipp Rech wrote:

> hello,
> 
> thanks you Joerg that helped me a lot. And you are rigth about the default
> way, but i wasn't aware of the function Form.js in this case. Good
> to know where this file is, thanks!
> 
> my question remaning is how to bind several forms. do i have to call the
> handleForm function seperatly for each form or can i pass several bindingURI's
> 
> and from-definitions in one sitemap match area.

The default handles only one form on a page, not many forms. CForms is 
not even really multiple-forms-aware, but taking care about some things 
should make it possible.

1. handleForm() instantiates the form. If you need multiple forms, you 
also need multiple instances, what you have already done (in the private 
mail):

var form1 = new Form("cform-definitions/widgets_table_event.xml");
var form2 = new Form("cform-definitions/widgets_table_goods.xml");
var form3 = new Form("cform-definitions/widgets_table_person.xml");
var form4 = new 
Form("cform-definitions/widgets_table_means_of_transport.xml");

To complete the form instances you also need to create a binding for each:

form1.createBinding("binding1.xml");
form2.createBinding("binding2.xml");
...

If you need to load some values you also need to load them for all form 
instances:

form1.load(bean1);
form2.load(bean2); //or bean1 again
...

The same is true for the save later.

So the binding framework has absolutely no problems with multiple form 
instances. Displaying the form and handling a form submit is much more 
interesting. I don't know exactly how you can make it work, probably by 
passing the form instances to the FOM context:

cocoon.sendPageAndWait("confrim_event", {"form1": form1, "form2": form2, 
...});

Maybe someone has already tested it.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Usage of "form.createBinding" compared with "form.load"

Posted by Philipp Rech <re...@iuw.fh-darmstadt.de>.
hello,

thanks you Joerg that helped me a lot. And you are rigth about the default
way, but i wasn't aware of the function Form.js in this case. Good
to know where this file is, thanks!

my question remaning is how to bind several forms. do i have to call the
handleForm function seperatly for each form or can i pass several bindingURI's
and from-definitions in one sitemap match area.

thanks again...
regards from the Bodensee!
phil


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Usage of "form.createBinding" compared with "form.load"

Posted by Joerg Heinicke <jo...@gmx.de>.
On 13.12.2004 13:26, Philipp Rech wrote:

>>You need both. createBinding with the binding file name tells the forms 
>>framework how to bind, load and save tells what to bind to.

> but it is still not clear since i don't use form.createBinding in my example
> which is working. I just call load and save and the Sitemap tells the CForms
> where the binding file is rigth?

No, somewhere it must be called. In the sitemap you only pass a 
parameter to the flow script. Somewhere this parameter must be read. If 
you use the default way (what I guess from your function call to 
handleForm()) it is done in the file Form.js, which is in 
src/blocks/forms/java/org/apache/cocoon/forms/flow/javascript (or after 
build in the webapp's lib dir in cocoon-forms-block.jar).

>  <map:call function="handleForm">

This call to handleForm is the secret, it does the rest for you.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Usage of "form.createBinding" compared with "form.load"

Posted by Philipp Rech <re...@iuw.fh-darmstadt.de>.
> You need both. createBinding with the binding file name tells the forms 
> framework how to bind, load and save tells what to bind to.
> 
> Joerg


Thank you Jeorg, 
but it is still not clear since i don't use form.createBinding in my example
which is working. I just call load and save and the Sitemap tells the CForms
where the binding file is rigth? So why should I use
form.createBinding(binding.xml) ? My guess was that i dont have to declare this
in the Sitemap:
 
 <map:call function="handleForm">
      <map:parameter name="function" value="myBinding"/>
      <map:parameter name="form-definition" value="form.xml"/>
      <map:parameter name="bindingURI" value="binding.xml"/>
   </map:call>

Otherwse "Binding.xml" woudld be declared twice? how would you handle the
binding for more than 1 form? Do i need several handeFrom sitemap entries as
above or could i put more bindingURI's and form-definitions as  <map:parameter
... /> and do my case switch within the mybinding function?

Thanks again,
phil



  

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Usage of "form.createBinding" compared with "form.load"

Posted by Joerg Heinicke <jo...@gmx.de>.
On 13.12.2004 12:34, Philipp Rech wrote:

> function myBinding(form) {
>    var bean = new Packages.foo.bar.cocoonBean();
>    form.load(bean);
>    form.showForm("registration-display-pipeline");
>    form.save(bean);
>    cocoon.sendPage("registration-success-pipeline", {"model": bean});
> }

> how does " form.createBinding("my_binding.xml"); " 
> (which i found in the flowscript of the samples folder) work? Is it 
> diffrent/better than my version? If i use form.createBinding
> do i still have to use the same sitemap as above?

You need both. createBinding with the binding file name tells the forms 
framework how to bind, load and save tells what to bind to.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org