1 Reply Latest reply on Jul 27, 2007 2:19 PM by Norman Richards

    Multiple component instances or how to use a component multi

    Patrick Ruhkopf Newbie

      Hi all,

      I really love bijection; it makes things so much easier. However, I have a requirement that makes it somehow hard to use contextual components.

      Let's suppose we have a Checkout page, were you can enter shipping and a payment addresses. These addresses obviously belong to a model of the same type. Let us further assume, that entering an address triggers some logic (beyond validation) so we need a controller, say:

      public class CheckoutAddressController {
       // maybe a persistence manager
       @In SomeService service
       // our model
       private Address address;
       // [...]
       // some logic, getter / setter etc

      Now on my checkout page, I want my address forms to have the above controller as a backing bean. So I need two instances of the same component on the same page. From the manual I read that maybe @Role could help here. But if the designer chooses to add another address form, I would have to add another Role. What if the designer wants to add 100 addresses? (yes, he's a maniac)

      Can composition help? I thought something like this?

      public class CheckoutPage
       @In(scope=ScopeType.STATELESS, create=true)
       CheckoutAddressController c1;
       @In(scope=ScopeType.STATELESS, create=true)
       CheckoutAddressController c2;
       // or even
       List<CheckoutController> ctls;
       @Create public void create() {
       ctls = new ArrayList...
       ctls.add(Component.getInstance("checkoutAddressController", ScopeType.STATELESS, true))

      Will this work?
      Are there other solutions?
      Am I making things to complicated?