5 Replies Latest reply on May 21, 2007 8:16 AM by Hannes Schulz

    Question On @Datamodel Outjection

    Hannes Schulz Newbie


      i have a problem outjecting a datamodel.

      i have a class the holds the business logic for a calculation process. It holds the Entity Calculation.class where the data is stored. during the calculation i create another object that holds the response information.

      public class CalculationManagerBean implements CalculationManager{
       ExpressCalculator expresscalculator;
       BudgetOverview budgetOverview;
       public void init(){
       log.debug("initialize new calculation entity");
       calculation = new Calculation(user);
       /*** business logic ***/
       public void executeExpressCalculation(){
       budgetOverview = expresscalculator.calculate(calculation);

      public class ExpressCalculatorBean implements ExpressCalculator {
       public BudgetOverview calculate(Calculation calculation) {
       // initialise BudgetOverview
       BudgetOverview budgetOverview = new BudgetOverview();
       //some code
       // this is the datamodel
       Set<CostItem> costItems = calculateInstallationCosts();
       return budgetOverview;
       // some functions

      and here is the class BudgetOverview

      public class BudgetOverview{
       // some attributes
       // the datamodel
       public Set<CostItem> costitems;
       // getter and setter methods

      So the problem is:
      In the view I can display all attributes from the budgetOverview except the datamodel selectitems. But i can e.g. display the size of the datamodel. So it is set properly just not outjected.
      If i change the code and outject the datamodel in the CalculationManager class and initialize it via a getter method from the BudgetOberview it works fine.

      I have no clue if i made a mistake or the overall concept of outjecting an object that outjects a datamodel doesnt work.

      Help would be great. and i hope you could follow this explanation.


        • 1. Re: Question On @Datamodel Outjection
          Carsten Hoehne Master

          what are you trying to do? Show the xtml pages.
          But, nevertheless, your code looks not quite correct.

          You do have a bean called budgetOverview in Conversation scope. And you try to outject the same name to conversation scope in scmanager.
          I do not understand whta you are trying to do.
          For your Datamodel costitems you need an initialization method. Either a factory or a method called from user interface would do the job.
          These concepts are well described in the seam documentation and are covered in the seam examples.

          But trying to outject an object which is already setup by seam, semms not right to me.

          • 2. Re: Question On @Datamodel Outjection
            Hannes Schulz Newbie


            i work mainly with 4 classes.

            - serves the business logic for the interaction with the user
            - holds a Calculation Object

            - Entity Bean
            - holds all data provided by the user

            - executes a calculation for a passed Calculation object
            - returns a BudgetOverview object

            - holds all data which should be returned to the user

            1. every time the user starts a calculation a (long running) conversation is started and a Calculation object is created which holds all data.
            2. When the user has passed all information a calculation is executed. and the response is stored in the BudgetOverview object
            3. the CalculationManager gets this BudgetOverview object and outjects it to the conversation scope. Then the user is redirected to the page where the response is rendered and after that the conversation ends.

            And within the BudgetOverview there is the DataModel selectitems which should also be outjected to the conversation scope.

            the part of the xhtml looks like that:

            <ui:define name="content">
             <h1>Budget Overview</h1>
             <span>BuildingTyp: </span>
             <h:outputText value="#{budgetOverview.buildingType}"/><br/>
             <span>Area: </span>
             <h:outputText value="#{budgetOverview.area}"/>
             <h:dataTable value="#{costitems}" var="item">
             ... columns

            works fine fot the #{budgetOverview.attributes} but not for the @Datamodel

            thanks for help,

            • 3. Re: Question On @Datamodel Outjection
              Hannes Schulz Newbie

              the @Datamodel selectitems is initialized by the ExpressCalculator 's method "calculateInstallationCosts()". it executes a private method which returns the Set. I just did not write it down here. selectitems is properly initialized because i can e.g display the size of it by writing a method in BudgetOverview

              public int getSize() {
               return selectitems.size();

              and display it like

              <h:outputText value"#{budgetOverview.size}"/>

              • 4. Re: Question On @Datamodel Outjection
                Carsten Hoehne Master

                now it is hopefully clear to me.
                You have an object 'budgetOverview' which is managed by seam, due to the @name annotation .

                At some stage in your workflow an object called budgetOverview is created (new ...) This object is NOT managed by seam. And you are outjecting this object into the same scope as the seam managed object resides in.

                So the datamodel can not be outjected, since you are not having a managed object in the scope.

                You should not create, with new, the budgetOverview object. Try to inject this bean into expresscalculator.

                From your code i suppose that you are not familar with the seam way of programming. Try to investigate the seam examples until you understand them. Or buy the very good new seam book, read documentation and experiment for yourself.

                If you have questions abourt the examples or documentation do not hesitate to ask here.

                • 5. Re: Question On @Datamodel Outjection
                  Hannes Schulz Newbie

                  ok thanks for your help. i understand your point.

                  i have to think about it...