4 Replies Latest reply on Oct 2, 2012 10:45 AM by crewman

    Seam components isn't injected within an ExtendedDataModel child

    crewman

      I'm trying to use a child of Seam's ExtendedDataModelClass as a data source for rich:dataTable component:

      {code:xml}<rich:dataTable id="docPackList" var="pack" width="100%" rows="25" value="#{specDocPackageList.dataModel}">

      ...

      </rich:table>

      {code}

      Within this child's walk() method I call a getResultList() method of controller derived from Seam's EntityQuery. This controller has some fields injected with Seam:

      {code}@Name("specDocPackageList")

      @Scope(ScopeType.CONVERSATION)

      public class SpecDocPackageList extends EntityQuery<DocPackage> {

          @In(create = true, value = "orgunitList")

          private OrgUnitList orgUnitListController;

          public OrgUnitList getOrgUnitListController() {

              return orgUnitListController;

          }

          public void setOrgUnitListController(OrgUnitList orgUnitListController) {

              this.orgUnitListController = orgUnitListController;

          }

          private SelectableQueryDataModel entityQueryDataModel;

          @Override

          public DataModel getDataModel() {

              if (entityQueryDataModel == null) {

                  entityQueryDataModel = SelectableQueryDataModel.getInstance(this);

              }

              return entityQueryDataModel;

          }

          ...

      }

      public class SelectableQueryDataModel<T, K> extends ExtendedDataModel {

          private EntityQuery<T> dataProvider;

          public SelectableQueryDataModel(EntityQuery<T> query) {

              dataProvider = query;

              ...

          }

          public static SelectableQueryDataModel getInstance(EntityQuery query) {

              return new SelectableQueryDataModel(query);

          }

          public void walk(FacesContext facesContext, DataVisitor dataVisitor, Range range, Object o) throws IOException {

              ...

              for (T item : this.dataProvider.getResultList()) {

                  ...

              }

              ...

          }

      }

      {code}

      The problem is I have null in specDocPackageList.orgUnitListController when specDocPackageList.getResultList() is called from SelectableQueryDataModel.walk() method. No excpetion is thrown at that point. However, this field is injected in the right way when getResultList() method is called to get data for rich:dataTable:

      {code:xml}<rich:dataTable id="docPackList" var="pack" width="100%" rows="25"

          value="#{specDocPackageList.resultList}">

      ...

      </rich:table>

      {code}

      Seam 2.2.0.GA and RichFaces 3.3.3 is used.


      Why doesn't Seam inject this field in the first case and do that in the second one?

        • 1. Re: Seam components isn't injected within an ExtendedDataModel child
          mkouba

          Hi,

          I think it's null because of the bijection is not performed. Seam bijection (in/out) is performed dynamically every time a component method is invoked. However SelectableQueryDataModel is not a Seam component. On the other side #{specDocPackageList.resultList} results in a Seam component invocation...

          • 2. Re: Seam components isn't injected within an ExtendedDataModel child
            crewman

            SelectableQueryDataModel is called indirectly, through the getDataModel() method of specDocPackageList component. Shouldn't bijection be performed on specDocPackageList.getDataModel() method invocation before call SelectableQueryDataModel ? Moreover, shouldn't bijection be performed on invocation of method getResulList() of specDocPackageList component within SelectableQueryDataModel.walk() method?

            • 3. Re: Seam components isn't injected within an ExtendedDataModel child
              mkouba

              Well, not really. Firstly note that when the invocation of SpecDocPackageList.getDataModel() completes disinjection is performed (null out any @In attributes) and this happens before walk() method is called. Also bijection wil not be performed during invocation of getResultList() within walk() method because it is not invoked on the component proxy but direct reference (BijectionInterceptor may not be applied). I think something like ((SpecDocPackageList)Component.getInstance(SpecDocPackageList.class, ScopeType.CONVERSATION, false)).getResultList() could work...

              1 of 1 people found this helpful
              • 4. Re: Seam components isn't injected within an ExtendedDataModel child
                crewman

                Thanks, Martin. Your answers are really informative and helpful for me.