4 Replies Latest reply on Aug 26, 2009 11:34 PM by aozoren

    injection problem with entityhome

    aozoren Newbie
      hi - this seems to be a 2.1.2 problem..

      i try to inject/use EventHome as below but it does not get injected.. i can verify that EventHome does get created.. any idea on what is going on? thanks.

              @In
              private EventHome eventHome;
             
          public EventTagList()
          {
              setEjbql("select eventTag from EventTag eventTag where eventTag.event.id = " + eventHome.getInstance().getId());
          }

        • 1. Re: injection problem with entityhome
          aozoren Newbie

          update.. EventHome in question is plain EntityHome derived 'home'.. Seam's 'entityManager' is injected fine..

          • 2. Re: injection problem with entityhome
            aozoren Newbie

            eventHome is available on the page so the page renders if i don't include eventTagList.. eventHome is always null in eventTagList code..


            @Name("eventHome")
            @Scope(ScopeType.SESSION)
            public class EventHome extends EntityHome<Event>
            {
                @RequestParameter Long eventId;
            
                @Override
                public Object getId()
                {
                    if (eventId == null)
                    {
                        return super.getId();
                    }
                    else
                    {
                        return eventId;
                    }
                }
            
                @Override @Begin(join=true)
                public void create() 
                {
                    super.create();
                    getInstance().setCreateOn(new Date());
                    System.out.println("*** event begun");
                }
            }
            






            @Name("eventTagList")
            public class EventTagList extends EntityQuery<EventTag>
            {
                 @Logger
                 Log log;
                 
                 @In
                 private EventHome eventHome;
                 
                public EventTagList()
                {
                     log.info(eventHome);
                     
                    setEjbql("select eventTag from EventTag eventTag"); // where eventTag.event.id = " + eventHome.getInstance().getId());
                }
            }
            




            event.xhtml..




                <h:form id="eventForm">
            
                    <rich:panel>
                        <f:facet name="header">event</f:facet>
            
                        <s:decorate template="layout/edit.xhtml">
                            <ui:define name="label">description</ui:define>
                            <h:inputText required="true"
                                         value="#{eventHome.instance.description}"/>
                        </s:decorate>
            
                        <div style="clear:both"/>
            
                    </rich:panel>
            
                    <div class="actionButtons">
                        <h:commandButton id="save"
                                      value="Save"
                                     action="#{eventHome.persist}"
                                   rendered="#{!eventHome.managed}"/>
                        <h:commandButton id="update"
                                      value="Save"
                                     action="#{eventHome.update}"
                                   rendered="#{eventHome.managed}"/>
                        <h:commandButton id="delete"
                                      value="Delete"
                                     action="#{eventHome.remove}"
                                  immediate="true"
                                   rendered="#{eventHome.managed}"/>
                        <s:button propagation="end"
                                           id="cancel"
                                        value="Cancel"
                                         view="/eventList.xhtml"/>
                    </div>
            
                </h:form>
            
                 <s:div rendered="#{eventHome.managed}">
                <rich:panel>
                    <f:facet name="header">eventTagList</f:facet>
            
                    <div class="results">
            
                        <h:outputText value="No eventTag exists"
                                   rendered="#{empty eventTagList.resultList}"/>
            
                        <h:dataTable id="eventTagList" var="eventTag"
                                  value="#{eventTagList.resultList}"
                               rendered="#{not empty eventTagList.resultList}">
                            <h:column>
                                <f:facet name="header">tag</f:facet>
                                #{eventTag.tag}
                            </h:column>
                            <h:column>
                                <f:facet name="header">tag</f:facet>
                                #{eventTag.value}
                            </h:column>
                        </h:dataTable>
            
                    </div>
            





            • 3. Re: injection problem with entityhome
              Stuart Douglas Master

              Injection is not availbile in the constructor (How do you expect seam to inject something before the object is created?).


              Put the login in an @Create method instead.

              • 4. Re: injection problem with entityhome
                aozoren Newbie

                Stuart -


                Your comment made me realize that wizard created a constructor not the usual getEjbql as in previous releases..


                Thanks, -a


                @Name("eventTagList")
                public class EventTagList extends EntityQuery<EventTag>
                {
                     @Logger
                     Log log;
                     
                     @In
                     private EventHome eventHome;
                     
                    @Override
                    public String getEjbql() 
                    {
                         return "select eventTag from EventTag eventTag where eventTag.event.id = " + eventHome.getInstance().getId();
                    }
                }