5 Replies Latest reply on Jul 8, 2011 9:48 AM by juankprada

    Navigate to another page, a4j:commandButton

    anna-lenasundin

      Hi all,

      I want to navigate to another page using an a4j:commandButton.

      I can navigate with a a4j:htmlCommandLink but not with a a4j:commandButton.

       

      Is there a way to solve this?

       

      Regards

        • 1. Re: Navigate to another page, a4j:commandButton
          juankprada

          Hi,

           

          Can you show us how are you using a4j:commandButton and the error you get when you use it?

          • 2. Re: Navigate to another page, a4j:commandButton
            anna-lenasundin

            Hi,

             

            I don't get any error messages.

             

            <a4j:commandButton value="Save" ajaxSingle="true"

                                action="#{bean.update}"   

                                actionListener="#{navigationBean.setPage}"                

                                oncomplete="if(!#{bean.storeOutcome})Richfaces.showModalPanel('messageWindow');"

                                reRender="messageWindow" >

                                 <f:param name="current" value="/xxx/show.jsp" />

                                                   

                                </a4j:commandButton>

             

            Thanks

            • 3. Re: Navigate to another page, a4j:commandButton
              juankprada

              can you also paste the code of your beans? at least the code involved with this commandButton

              • 4. Re: Navigate to another page, a4j:commandButton
                anna-lenasundin

                public abstract class NavigationBean extends BaseBean {

                    protected String page;

                    protected String popup;

                    protected String script;

                   

                    public void setPage() {

                        ExternalContext ext = getExternalContext();

                        Map<String, String> reqMap = ext.getRequestParameterMap();

                        page = (String) reqMap.get("current");       

                    }

                   

                   

                    public String getPage() {

                        return page;

                    }

                   

                    public void setPage(ActionEvent ae) {

                        ExternalContext ext = getExternalContext();

                        Map<String, String> reqMap = ext.getRequestParameterMap();

                        page = (String) reqMap.get("current");       

                    }

                .....

                }

                 

                public class xxBean extends UserBean {

                 

                private boolean storeOutcome = false;

                  

                public void setStoreOutcome(boolean storeOutcome) {

                        this.storeOutcome = storeOutcome;

                    }

                 

                    public boolean isStoreOutcome() {

                        return storeOutcome;

                    }

                 

                public String updateXX(){

                     storeOutcome = false;       

                        if (xxx != null) {

                               .............

                               storeOutcome = true;

                               return Constants.SUCCESS_OUTCOME;

                           }

                        

                            // if not found - fall through to error exit.

                        }

                        return Constants.FAILURE_OUTCOME;

                    }

                .......

                }

                • 5. Re: Navigate to another page, a4j:commandButton
                  juankprada

                  I think i understand what you are doing, but can you tell me what is the value of Constants.FAILURE_OUTCOME and Constants.SUCCESS_OUTCOME?

                   

                  What I think you are doing is when you click on the button, the action listener should be executed, and 'page' parameter should be set. Not sure where you are using that parameter, but i guess it is not that important. Now, after the actionListener executes, the action method should be executed, that is the one that will send your app to the new page right?. I see that in the method updateXX() which is the one i think is executed in the action parameter, has an extra }. If its like that, it should not even compile. Now you validate a xxx variable that is not declared in that code, can you show the complete code to see what is this variable holding? and where are you setting it?

                   

                  I would replace the f:param with f:setPropertyActionListener. so your NavigationBean should look something like this

                   

                  public abstract class NavigationBean extends BaseBean {

                      protected String page;

                      protected String popup;

                      protected String script;

                     

                      public void setPage(String page) {

                        this.page = page

                      }

                     

                     

                      public String getPage() {

                          return page;

                      }  

                  .....

                  }

                   

                  And your xhtml would look something like this:

                   

                  <a4j:commandButton value="Save" ajaxSingle="true"

                                      action="#{bean.update}"   

                                      actionListener="#{navigationBean.setPage}"                

                                      oncomplete="if(!#{bean.storeOutcome})Richfaces.showModalPanel('messageWindow');"

                                      reRender="messageWindow" >

                              <f:setPropertyActionListener target="#{navigationBean.page}" value="/xxx/show.jsp" />

                                                         

                  </a4j:commandButton>

                   

                  Without the appropriate code i can't really help you.