0 Replies Latest reply on Aug 28, 2009 11:28 AM by Matthias Age

    Design question about dependeny-injection

    Matthias Age Newbie


      I use a rich:datatable which uses a custom DataModel object.

      The DataModel class needs a SearcherObject (this object executes the search).
      The searcher-object on the other side nees a CriteriaObject (a stateful object that holds the search-paramter values which the user entered) for executing the search.
      Here's a simple sketch of the two classes:

      class DataModel
        SearcherObject mySearcherObject
      class SearcherObject
        CriteraObject myCriteriaObject

      Everything worked fine.

      But now I have the situation that on another page I would like to use the same classes/components but the searcher-object should use another criteria-object (for example with a shorter lifecycle, registered with the @Role-annotation with another scope). I didn't find a way for doing this. I copied the classes:


        class DataModelA
          SearcherObjectA mySearcherObjectA
        class SearcherObjectA
          CriteraObjectA myCriteriaObjectA

      Page B:

        class DataModelB
          SearcherObjectB mySearcherObjectB
        class SearcherObjectB
          CriteraObjectB myCriteriaObjectB

      That approach is doubling the classes (sure, I can move the common-behaviour in super-classes, so the actual classes are very short) and not very elegant.

      Isn't there a way to inject dynamically other components (depending on the page, the name of the component, the context, ...)?

      I know that in the @In-annotation I can use value-expressions, but I can't think of a way to use this feature (somehow I would have to set a context-variable before navigating to the page, for example in a page.xml file, but this approach doesn't seam very appealing to me).

      If someone has some hints or ideas, please le me know,