1 2 Previous Next 16 Replies Latest reply on Jul 26, 2007 1:52 PM by Thomas Gerhards

    The Right Scope

    Thomas Gerhards Newbie

      Hi,

      I have a working little book search here. I is triggered from page 1 and the results are rendered on page 2 ("searchResultsPage").

      My question: In the code below I bind the DataModel object to the session just to have it available on the page that the SLSB redirects to. I don't want that: How can I avoid the expensive session binding of the DataModel? Other scopes like EVENT or CONVERSATION don't seem to work... how would you do that?

      @Stateless
      @Scope(ScopeType.SESSION)
      @Name("bookSearch")
      public class BookSearchAction implements BookSearch {
      
       @In
       private SearchRequest searchRequest;
      
       @DataModel
       private List<SearchResult> searchResults;
      
       public BookSearchAction() {}
      
       public String search() {
      
       searchResults = new ArrayList();
       searchResults.add(...)
       ...
      
       //redirect
       return "searchResultsPage";
       }
      }


      Thanks!

        • 1. Re: The Right Scope
          fhh Expert

          Are you rendering or redirecting to searchResultsPage?

          Regards

          Felix

          • 2. Re: The Right Scope
            Thomas Gerhards Newbie

            Hi fhh,

            as BookSearchAction.search is called from page 1 and displays page 2 after that I would call it a redirect... this is how page 1 and 2 look like:

            Page 1:

            <h:form>
             <h:inputText value="#{searchRequest.keyword}" size="20"/>
             <h:commandButton value="#{msg.search}" action="#{bookSearch.search}" class="button"/>
            </h:form>


            Page 2("searchResultsPage"):
            <h:dataTable class="dataTable" value="#{searchResults}" var="result" rendered="#{searchResults.rowCount>0}">
             <h:column>
             <b><h:outputText value="#{result.title}"/></b>
            ...


            • 3. Re: The Right Scope
              Thomas Gerhards Newbie

              Dear Seam community, that should be an easy question for you...

              • 4. Re: The Right Scope
                Ning Zhao Apprentice

                You may want to try to make the searchResults list managed, i.e, remove the @DataModel annotation, write getter/setter for the searchResults list and do not forget to also write them in the business interface. Access searchResults using bookSearch.searchResults. (I assume the name of your action bean is "bookSearch", you may need to adjust it accordingly. )

                • 5. Re: The Right Scope
                  Thomas Gerhards Newbie

                  @ellenzhao:
                  That does not work, I've just tried it. bookSearch.searchResults is not available on page 2, even if I change BookSearchAction from a SLSB into a SFSB.

                  @All: Seam community, you know the solution, I'm sure. That has to work somehow, there must be a solution! This is _SEAM_!

                  • 6. Re: The Right Scope
                    Alex Ka Novice

                    can you post here your pages.xml ;-)

                    • 7. Re: The Right Scope
                      Alex Ka Novice

                      I think you should find an example (eg.: hotel booking) of what you're trying to do and copy the working code.

                      I think you have to use conversation scope. Therefore you should @Begin a conversation with search(). Maybe with join=true

                      • 8. Re: The Right Scope
                        Thomas Gerhards Newbie

                        @wise_guybg:
                        The hotel booking example does not perform a redirect. The search is triggered from the same page where the results are rendered.

                        I need the results on a page that is not the page that the action was called from.

                        Should it really be so difficult??

                        • 9. Re: The Right Scope
                          Alex Ka Novice

                          Hi JUnkie,

                          You have not provided the code from pages.xml that I requested from you. I wanted you to post it here because yesterday a colleague was having a problem and the solution was fixing pages.xml

                          The solution you need should not be difficult, no. You have to understand what you have with Seam and how you can use it.

                          If the redirect is really a problem you might execute an action (MethodBinding) with your redirect. Something that will start your conversation. You haven't commented on the @Begin that I think you're missing

                          I need the results on a page that is not the page that the action was called from.


                          My prescription would be: proper conversation handling and proper pages.xml

                          You have posted a session scoped bean and some jsf code.

                          I think that with minor modification the hotel booking example is also valid...

                          • 10. Re: The Right Scope
                            Thomas Gerhards Newbie

                            @wise_guybg:
                            Thanks for your reply! My pages.xml is empty (it's a brand new project).

                            Regarding "@Begin": I believe that cannot be used on a SLSB, is that correct? Then I would need to change to a SFSB (which I thought I could avoid somehow...)

                            If you have an idea, a cool entry in pages.xml or so, please let me know!

                            Thanks!

                            • 11. Re: The Right Scope
                              Alex Ka Novice

                              Hi JUnkie,

                              I couldn't remember what SLSB and SFSB stood for so I searched on the Internet. Yes, I'm that dumb :) This is an article that might be interesting:
                              http://weblogs.java.net/blog/schaefa/archive/2003/10/slsb_sfsb_meani.html

                              Anyways, maybe you should have your SLSB but use it with a SFSB that will guide the conversation and eventually contain the info from the :

                              @DataModel
                              private List<SearchResult> searchResults;
                              


                              I am not sure if you should separate logic this way though. I think this is what's commented in the article.

                              About pages.xml, I don't recall if there is anything that can help you.

                              There is also the option to manually work with conversations like this:
                              <h:outputLink value="main.seam" target="_blank">
                               <s:conversationId/>
                               <s:conversationPropagation propagation="join"/>
                               <h:outputText value="Open New Tab"/>
                              </h:outputLink>
                              


                              but in my opinion this isn't applicable either.

                              So you have to @Begin a conversation somehow.

                              • 12. Re: The Right Scope
                                None None Master

                                My understanding is that conversation scope is almost always the right scope. If you're doing a search, you want conversations so that users can do multiple different searches in different tabs, right?

                                • 13. Re: The Right Scope
                                  Thomas Gerhards Newbie

                                  @SmokingAPipe:
                                  Thanks, I do not care for multiple different searches in different tabs yet, I just want the DataModel available on the page that I redirect to.

                                  • 14. Re: The Right Scope
                                    Thomas Gerhards Newbie

                                    Okay, I found it. I used Ajax4JSF (org.ajax4jsf.Filter in web.xml) which destroys all Seam conversation (even a very short one like a simple redirect).

                                    I have added SeamRedirectFilter to web.xml(org.jboss.seam.servlet.SeamRedirectFilter) which solved all my problems.

                                    BUT WHY is SeamRedirectFilter deprecated??? It is needed for Ajaja4JSF, look here:
                                    http://labs.jboss.com/jbossajax4jsf/docs/devguide/en/html/SettingsForDifferentEnvironments.html#JBossSeamSupport

                                    Mr Gavin King: It took me days (and I worked into the nights) to find out why my first Seam app does not do what it should. Could you take 1 minute of your time and answer why the SeamRedirectFilter is deprecated?

                                    1 2 Previous Next