7 Replies Latest reply on Jan 12, 2007 11:30 AM by antispart

    invoke a action method everytime a page is accessed FROM ano

    antispart

      I have a SFSB in conversation scope. But I want to have the option of passing it request parameters.

      So, for example:

      <s:link value="Search" action="search">
      <f:param name="searchPattern" value="#{oldbean.searchPattern}"/>
      </s:link>


      Now, I need some way of telling the searchActionBean to use the RequestParameter searchPattern instead of another one living in conversation scope (they cant be the same property b/c of some other complication).

      Now, if i put an action=... in pages.xml this will get called everytime the page/view is accessed. Instead I only want this action method to be invoked when the request parameter comes in. I thought I could stick a call to this method in the setter but the setter seems to be called regardless of whether the RequestParameter is specified.

      Anyone have any ideas what i can do?

        • 1. Re: invoke a action method everytime a page is accessed FROM
          pmuir

          I think that the @RequestParameter will only be not-null when you have an f:param specified. So use an action method run through pages.xml, check for not-null, and act accordingly.

          • 2. Re: invoke a action method everytime a page is accessed FROM
            antispart

            Thanks petemuir.

            I have the following code:

            actionBean

             @Begin(join=true)
             public void foo() {
             if(player!=null)
             log.debug("set");
             }
             public void setBar(String bar) {
             this.bar= bar;
             }
             public String getBar) {
             return bar;
             }
            


            pages.xml
            <page view-id="/players/plays.xhtml" action="#{playerPlayAction.foo}"/>
            


            xhtml
            <s:link ... >
             <f:param name="bar" value="test"/>
            </s:link>
            


            While foo() gets called every time the page is accessed. the setBar() method is never called.

            If I add:
            <param name="bar" value="#{actionBean.bar}"/>
            

            to the pages.xml then the setBar() is called, BUT.

            Once i've navigated to the page 1 time from the s:link now the bar property is always not-null (note that this is a conversation scoped bean).

            Is there any solution to this?

            • 3. Re: invoke a action method everytime a page is accessed FROM

              If you need a very peculiar strategy, why not just look up the value as a request attribute directly?

              • 4. Re: invoke a action method everytime a page is accessed FROM
                pmuir

                1) If you put a

                <param name="bar" value="#{actionBean.bar}"/>
                into pages.xml it causes the param to be propagated.

                2) Try this in the action bean (without param in pages.xml)

                @RequestParameter
                private String bar;
                
                @Begin(join=true)
                public void foo() {
                 if(player!=null)
                 log.debug("set");
                }


                • 5. Re: invoke a action method everytime a page is accessed FROM
                  antispart

                  petemuir,

                  I tried:

                  action bean:

                   @RequestParameter
                   private String bar;
                  
                   @Begin(join=true)
                   public void foo() {
                   if(bar!=null)
                   log.debug("set");
                   }
                  


                  xhtml:
                  <s:link ...>
                   <f:param name="bar" value="testtest"/>
                  </s:link>
                  


                  pages.xml:
                  <page view-id="/players/plays.xhtml" action="#{playerPlayAction.foo}"/>
                  


                  Now, when foo() gets called with the s:link the @RequestParameter bar is never set. But if i use an h:outputLink or just type the url string myself then the @RequestParameter does get set. Is this expected behavior?

                  The advantage of s:link is that I could continue a conversation (add "join=true" to the foo() method) AND pass in params via a @RequestParam.

                  Is this not meant to work with s:link or am I do something wrong?

                  • 6. Re: invoke a action method everytime a page is accessed FROM
                    pmuir

                     

                    Now, when foo() gets called with the s:link the @RequestParameter bar is never set. But if i use an h:outputLink or just type the url string myself then the @RequestParameter does get set. Is this expected behavior?


                    Not sure, sorry. You could just use a commandLink with s:conversationPropagation I think.

                    • 7. Re: invoke a action method everytime a page is accessed FROM
                      antispart

                      Thanks. Your help is always appreciated.