9 Replies Latest reply on Apr 26, 2008 3:01 AM by clatimer

    Outjection Ignored...

    clatimer

      I am having a problem getting objects to outject properly. 


      I have a stateless session bean as follows



      @Stateless
      @Name("smaListAction")
      public class SmaListAction implements SmaListActionLocal
      {
          @In(create=true)
          DailySmaLevelDAO smaLevelDAO;
          
          @In(create=true)
          DailyProcessingStatusDAO dailyProcessingDAO;
          
          @Out(required=true, scope=ScopeType.EVENT)
          List<DailySmaLevel> smaLevels;
          
          @Out(required=true, scope=ScopeType.EVENT) 
          Date asOfDate;
          
          public String viewSmaList()
          {
           asOfDate = dailyProcessingDAO.getCurrentAsOfDate();
           System.out.println(asOfDate);
           smaLevels = smaLevelDAO.findDailySmaLevelsWithinRange(asOfDate);
           System.out.println("Retrieved: " +smaLevels.size());
           return "success";
          }
      }



      I am then trying to use the outjected objects asOfDate and smaLevels in my ui component:


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <html xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core">
      
           <ui:composition template="/templates/layout.xhtml">
                <ui:define name="left">
                     Stocks within 1/2 percent of their 50 day SMA for as of date #{asOfDate}
                     <h:dataTable value="#{smaLevels}" var="smaLevel" >
                          <h:column>
                               <f:facet name="symbol">
                                    <h:outputText value="Symbol" />
                               </f:facet>
                               <h:outputText value="#{smaLevel.stockSummary.symbol}" />
                          </h:column>
                          <h:column>
                               <f:facet name="fiftyDaySma">
                                    <h:outputText value="50 Day SMA" />
                               </f:facet>
                               <h:outputText value="#{smaLevel.fiftyDaySma}" />
                          </h:column>
                          <h:column>
                               <f:facet name="hundredDaySma">
                                    <h:outputText value="100 Day SMA" />
                               </f:facet>
                               <h:outputText value="#{smaLevel.hundredDaySma}" />
                          </h:column>
                          <h:column>
                               <f:facet name="twoHundredDaySma">
                                    <h:outputText value="200 Day SMA" />
                               </f:facet>
                               <h:outputText value="#{smaLevel.twoHundredDaySma}" />
                          </h:column>
                     </h:dataTable>
                </ui:define>
           </ui:composition>
      </html>



      When I use my website to access the page, both the asOfDate and the smaLevels objects evaluate to null.  I have tried using both ScopeType.EVENT and ScopeType.PAGE and both times it evaluates to null.  However, when I annotate my action method viewSmaList with an @Begin(join=true) and set the scope of the outjected objects to ScopeType.CONVERSATION it gets put into the conversation scope as I expected.  There is really no reason to have a conversation for this interaction though; it truly is stateless.


      Can anyone help me understand why outjection is not working unless I use the conversational context?  According to the examples in the Seam Documentation section 3.3 Bijection I should be able to outject to any valid ScopeType I specify, so I'm pretty much stumped.


      Thanks in advance,


      Chris Latimer

        • 1. Re: Outjection Ignored...
          andygibson.contact.andygibson.net

          Hi Chris,


          I took a look at what you are doing, and tried it out myself with a basic example. It worked fine with a stateless bean outjecting to the event scope. I used a string in my example which was set when I called a method bound to a button.


          How are you setting the values for smaLevels? When is viewSmaList() being called? Can you check that it is being called?


          Cheers,


          Andy Gibson

          • 2. Re: Outjection Ignored...
            clatimer

            Hi Andy,


            Thanks for the reply.


            I am setting the values of smaLevels through a call to my DAO class which is also a stateless session bean.  I have verified that viewSmaList is being called two ways:



            1. The System.out.println statement prints out the size of the List and the asOfDate fine when I am using the EVENT or PAGE scopes.

            2. When I change the scope to CONVERSATION and annotate the viewSmaLevels method with an @Begin the objects are outjected correctly and the page renders fine.



            I am wondering if the problem may be in my navigation rule:


            <navigation from-action="#{smaListAction.viewSmaList}">
                 <rule if-outcome="success">
                      <redirect view-id="/pages/daily_sma_screen.xhtml" />
                 </rule>
            </navigation>



            I thought I read in the documentation that Seam would propagate outjected objects through a redirect, unlike request variables in JSP, but maybe I imagined that.


            When you got the example working what did your navigation in pages.xml look like?


            Maybe I'll re-read through the documentation section on navigation and see if it reveals anything.  Thanks for taking a look at this.


            Chris Latimer

            • 3. Re: Outjection Ignored...
              clatimer

              I'm having another problem along these same lines.  When I try to add a parameter to my redirect statement, it evaluates to null when the page is rendered as well.  Here's the code:


              <navigation from-action="#{smaListAction.viewSmaList}">
                   <rule if-outcome="success">
                        <redirect view-id="/pages/daily_sma_screen.xhtml" />
                             <param name="numDays" value="Fifty" />
                   </rule>
              </navigation>



              In this case when I try to use the JSF EL #{numDays} or the JSF tag

              <h:outputText value="#{numDays}"/>


              it also evaluates to null.


              It's like Seam doesn't recognize the EVENT or PAGE scopes at all...

              • 4. Re: Outjection Ignored...
                clatimer

                The above navigation rule should read:


                <navigation from-action="#{smaListAction.viewSmaList}">
                     <rule if-outcome="success">
                          <redirect view-id="/pages/daily_sma_screen.xhtml">
                               <param name="numDays" value="Fifty" />
                          </redirect>
                     </rule>
                </navigation>



                It is correct in my actual code, I just messed up typing it in my message...

                • 5. Re: Outjection Ignored...
                  clatimer

                  This last problem was fixed by adding a param element to the page element for the dailysmascreen.xhtml page.  Still have the first problem though...

                  • 6. Re: Outjection Ignored...
                    andygibson.contact.andygibson.net

                    Hey Chris,


                    Ok, your scenario is more complicated that the example I had since I was staying on the same page, and clicking a button that did nothing but outject the variables.


                    You are correct in that Seam will propagate some pieces across a redirect but not all. I'm guessing that it does not propagate Event or Page scoped items across which is reasonable. For Page scope, we've already moved to another page, and event scope could be too short a scope to live past the redirect.


                    Try this, set the Scope of the outjected variable to conversation, but don't start a new conversation i.e.


                      @Out(required=true, scope=ScopeType.CONVERSATION)
                        List<DailySmaLevel> smaLevels;
                    



                    The seam documentation says in section 6.1 :



                    Seam transparently propagates the conversation context (including the temporary conversation context) across
                    JSF postbacks and redirects.

                    If you make the variable conversation scoped, you don't have to start a new long running conversation, it will exist in the temporary conversation, and hopefully get propagated over the redirect.


                    Let me know if that does it, and if not, I'll create a more specific test case tomorrow, one that includes the redirect and navigation complexities you have.


                    Cheers,


                    Andy Gibson

                    • 7. Re: Outjection Ignored...
                      andygibson.contact.andygibson.net

                      OK, I have a quick fiddle around with the whole issue of passing data across redirections. If you give the outjection a conversation scope it should work. You do not have to begin a conversation, it just puts the data into the scope of the temporary conversation which does survive the re-direct.


                      Cheers,


                      Andy Gibson

                      • 8. Re: Outjection Ignored...
                        clatimer

                        Thanks for looking into this Andy.  What you've posted is helpful.


                        Maybe my problem is that the navigation rules I'm using always use redirect.  I'll mess around with it tonight and see if I change the navigation to use the render tag instead if I can get it working that way.



                        From the seam documentation:


                        3.1.2. Event context




                        The event context is the "narrowest" stateful context, and is a generalization of the notion of the web request context to cover other kinds of events. Nevertheless, the event context associated with the lifecycle of a JSF request is the most important example of an event context, and the one you will work with most often. Components associated with the event context are destroyed at the end of the request, but their state is available and well-defined for at least the lifecycle of the request.

                        When you invoke a Seam component via RMI, or Seam Remoting, the event context is created and destroyed just for the invocation.

                        It sounds like I should be able to use the Event context in Seam similarly to the way I used the Request context in Struts.  The way I'm interpreting this section, I should be able to outject to the Event scope, and have visibility to the event scope in the rendered page.  Since I am redirecting, however, it doesn't propagate the event objects after the render response phase.  Since the redirection sounds like it happens after the lifecycle ends, maybe by using the render tag it will make a difference.  I'll let you know the results of my experiment.


                        Chris Latimer

                        • 9. Re: Outjection Ignored...
                          clatimer

                          Both solutions work...


                          I can use the ScopeType.CONVERSATION and use a redirect in my navigation rules and it works fine.  I can also use ScopeType.EVENT in my page and change my navigation rules to use render instead of redirect and it still works fine.


                          Problem solved.


                          Thanks!


                          Chris