cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <br...@outerthought.org>
Subject Re: [woody] Multiple bindings?
Date Sun, 15 Feb 2004 08:18:36 GMT
On Sat, 2004-02-14 at 19:57, Mark Lundquist wrote:
> A form can only be bound to one model, but I need a form that has
> theeffect of being bound to 2 beans (so in MVC terms the one form
> wouldcomprise 2 views, one of each model).
> 
> Does anybody have any suggestions for how to achieve this?

yep.

First thing to know is that the binding is completely separate from the
form stuff, it's only the flowscript form object that integrates the two
to make them more convenient to use.

Basically you can get the idea again from looking what goes on in
woody2.js.

Here's just some pseudocode of how to do it.

First declare a function like this:

function createBinding(bindingURI) {
    var bindingManager = null;
    var source = null;
    var resolver = null;
    try {
        bindingManager = cocoon.getComponent(Packages.org.apache.cocoon.woody.binding.BindingManager.ROLE);
        resolver = cocoon.getComponent(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
        source = resolver.resolveURI(bindingURI);
        return bindingManager.createBinding(source);
    } finally {
        if (source != null)
            resolver.release(source);
        cocoon.releaseComponent(bindingManager);
        cocoon.releaseComponent(resolver);
    }
}

(this is mostly identical to the createBinding method in the form object)

then create the bindings like this:

var binding1 = createBinding("binding1.xml");
var binding2 = createBinding("binding2.xml");

and then for loading:

binding1.loadFormFromModel(form.form, bean1);
binding2.loadFormFromModel(form.form, bean2);

and for saving:

binding1.saveFormToModel(form.form, bean1);
binding2.saveFormToModel(form.form, bean2);

Thus when doing things this way, you don't need the form.load and
form.save methods.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


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


Mime
View raw message