1 2 Previous Next 21 Replies Latest reply on Jun 11, 2007 8:49 AM by Matt Drees

    @In (create=true)

    Mathew Blackberry Newbie

      I am recieving an error when I load my "gameHome" component. The error is as follows:

      org.jboss.seam.RequiredException: In attribute requires non-null value: gameHome.oppTeamHome
      


      My seam component is delcared as follows:

      @Name("gameHome")
      public class GameHome extends EntityHome<Game> {
      
       @In(create = true) TeamHome oppTeamHome;
       ...
      


      Is my understanding that if I use create=true that the instance will be created if it's value is null. Am I missing something?




        • 1. Re: @In (create=true)
          Christian Bauer Master

          Yes, it should be. Show TeamHome.java.

          • 2. Re: @In (create=true)
            Mathew Blackberry Newbie

            Here is the important part from TeamHome.java (as generated by seam-gen)


            @Name("teamHome")
            public class TeamHome extends EntityHome<Team> {

            private static final long serialVersionUID = -6503138100502127742L;
            @In(create = true)
            ClubHome clubHome;
            @In(create = true)
            GradeHome gradeHome;
            ...


            should the @Name here match the @In attributes name from GameHome.java?



            • 3. Re: @In (create=true)
              Mathew Blackberry Newbie

              The reason I have changed

               @In (create=true) TeamHome teamHome;


              to

               @In (create=true) TeamHome oppTeamHome;


              is because I also have a second TeamHome attribute in GameHome.java

              @In(create = true) TeamHome oppTeamHome;
              @In(create = true)
              RoundHome roundHome;
              @In(create = true)
              GroundHome groundHome;
              @In(create = true) TeamHome homeTeamHome;


              Do i need to rename TeamHome.java to OppTeamHome.java and make another similar class called HomeTeamHome.java.

              My database table Game has multiple foreign keys to the same table Team.



              • 4. Re: @In (create=true)
                Jonas Erma Newbie

                Use

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


                tazman

                • 5. Re: @In (create=true)
                  Mathew Blackberry Newbie

                  I have tried this with the same results.

                  • 6. Re: @In (create=true)
                    Christian Bauer Master

                    What do you want? Two local fields referencing the _same instance_ of the TeamHome component or two instances?

                    • 7. Re: @In (create=true)
                      Mathew Blackberry Newbie

                      They should both be referencing 2 separate instances.

                      • 8. Re: @In (create=true)
                        Christian Bauer Master

                        Interesting, I don't think this is actually possible.

                        • 9. Re: @In (create=true)
                          Mathew Blackberry Newbie

                          I should have said They should both be referencing a separate instance each.
                          not 2 instances each if that is not clear.

                          I have a set up simplified to the following.

                          Table Game
                          ========
                          game_id
                          home_team_id --> fkey to table team field team_id
                          opp_team_id --> fkey to table team field team_id


                          Table Team
                          ========
                          team_id
                          team_name




                          eg.


                          Table Game
                          ========
                          game_id | home_team_id | opp_team_id
                          -------------------------------------------------
                          1 | 1 | 2
                          2 | 3 | 2


                          Table Team
                          ========
                          team_id | team_name
                          --------------------------
                          1 | Team A
                          2 | Team B
                          3 | Team C


                          So what I want is to have is for the record with game_id 1 should have homeTeamHome pointing to an instance of team with team_id 1 (Team A) and oppTeamHome pointing to an instance of team with team_id 2 (Team B).

                          So from my facelet page i could reference Team B by #{gameHome.oppTeamHome.instance.team_name} and Team A by #{gameHome.homeTeamHome.instance.team_name}


                          • 10. Re: @In (create=true)
                            Christian Bauer Master

                            Do you really need this to be TeamHome components? If you are not editing the Team entity instances, you could just reference them directly in GameHome for display.

                            • 11. Re: @In (create=true)
                              Mathew Blackberry Newbie

                              I will also be adding new games to the table, The reason I am using the Home components is because this is the way seam gen did it for other table I have generated (they only had single foreign keys to any other table). I would like the option to be able to click a button to add an oponent team to the game and click a button to add a home team to the game, the same way seam gen does it. I will look into a direct reference to the entity from Game Home.

                              • 12. Re: @In (create=true)
                                Mathew Blackberry Newbie

                                In the end to get it working i duplicated TeamHome.java and renamed the original too.

                                Now i have HomeTeamHome.java and OppTeamHome.java

                                with seam names

                                @Name("homeTeamName")
                                &
                                @Name("oppTeamName")

                                respectively.

                                With a few changes to TeamList.xhtml, TeamList.page.xml, GameEdit.xhtml and GameEdit.page.xml (based on the versions generated by seam gen) I got the desired result.


                                GameEdit.page.xml

                                <param name="oppTeamTeamId" value="#{oppTeamHome.teamTeamId}"/>
                                <param name="homeTeamTeamId" value="#{homeTeamHome.teamTeamId}"/>


                                GameEdit.xhtml
                                (changes in bold/red)
                                <div class="actionButtons">
                                 <s:button value="Select Away Team"
                                 view="/TeamList.xhtml">
                                 <f:param name="from" value="GameEdit"/>
                                 <f:param name="forOppTeam" value="1"/>
                                 </s:button>
                                 </div>
                                


                                and

                                <div class="actionButtons">
                                 <s:button value="Select Home Team"
                                 view="/TeamList.xhtml">
                                 <f:param name="from" value="GameEdit"/>
                                 <f:param name="forHomeTeam" value="1"/>
                                 </s:button>
                                 </div>



                                TeamList.page.xml

                                <param name="forOppTeam"/>
                                <param name="forHomeTeam"/>



                                TeamList.xhtml


                                <s:link view="/#{empty from ? 'Team' : from}.xhtml"
                                 value="#{team.teamName}"
                                 id="team" rendered="#{not empty forOppTeam}">
                                 <f:param name="oppTeamTeamId" value="#{team.teamId}"/>
                                 </s:link>
                                 <s:link view="/#{empty from ? 'Team' : from}.xhtml"
                                 value="#{team.teamName}"
                                 id="team" rendered="#{not empty forHomeTeam}">
                                 <f:param name="homeTeamTeamId" value="#{team.teamId}"/>
                                 </s:link>



                                There is probably a nicer way to do the last block without making 2 separate links and only rendering the appropriate one based on the forXXXXTeam value being used. But my JSF knowledge is pretty minimal at the moment. A rendered attribute for the f:param tag would have been nice.

                                Thanks for all of your help

                                • 13. Re: @In (create=true)
                                  Glenn Marcus Newbie

                                  Why couldn't you use @Role to define 2 known context names for the same component? There is an example in the Seam Docs.

                                  • 14. Re: @In (create=true)
                                    Mathew Blackberry Newbie

                                    It would be nice that since OppTeamHome.java and HomeTeamHome.java are identical except for the class name and the seam @Name that I would be able to use a single class for both instances.

                                    1 2 Previous Next