1 Reply Latest reply on Jan 12, 2010 12:00 PM by mikkus70

    Same component name, different implementations?

    andyredhead

      Hi,


      I have come across an interesting Seam app design question.


      We have a Seam app where most of the UI logic is in conversation scoped ejb3 stateful session beans and the UI is built using JSF/Facelets and RichFaces (with the flow managed by a Seam pageflow). It works well :)


      Part of the app needs to know about the locale a customer is in and which warehouse will dispatch products to the customer. The way this information is derived is different depending on how the order was created (online v quote).


      I'd like to have a component OrderFulfillmentDetails which is used by the UI (and the other logic) to locate the necessary information and provide it to the other components. Ideally, we'd have a different implementation of OrderFulfillmentDetails, one for online orders and one for quotes but within the conversation the actual instance of the component would have the name OrderFulfillmentDetails so that el expressions in the UI pages can reference a single name (rather than doing horrible if this is a quote then show this div else show that div in the xhtml).


      So, when a conversation is started I'd like to inject (or otherwise create) a specific implementation of a seam component with a fixed name (implemented as a  stateful session bean).


      Does anyone have any pointers to how I might be able to do this?


      Thanks,


      Andy

        • 1. Re: Same component name, different implementations?
          mikkus70

          There are several ways of doing this, an easy one is to just create an alias to the correct component using a factory:


          <factory name="OrderFulfillmentDetails" value="#{orderFulfillmentManager.detail}" scope="CONVERSATION />
          



          Where orderFulfillmentManager is a component that determines which implementation to use and returns it. If it is easier, you can also use an expression:


          <factory name="OrderFulfillmentDetails" value="#{order.quote ? quotedOrderDetails : onlineOrderDetails}" scope="CONVERSATION" />
          



          Where order.quote is a property that evaluates to true if the order has a quote, false otherwise.