3 Replies Latest reply on Mar 5, 2010 3:44 AM by harut

    Opening links in new tabs/windows problem

    frisch

      I have the following problem: I use a4j:commandLink and h:commandLink in most of my views. When I right click on a link and choose "Open Link in New Tab" or "Open Link in New Window" the same page is displayed in the new tab/window and I need to click the link again in order to acces the desired page.

       

      Does anyone know what is causing this? How could I make it work so that the user gets the content of the desired page in the new tab/window?

       

       

      Thanks

        • 1. Re: Opening links in new tabs/windows problem
          harut

          Hi,

           

               If you have no ajax related functionality after clicking on a4j:cammandLink, and you use commandLinks just for opening new page based on some action functionality, then you can just use rest:link (RestFaces) instead of commandLink.

           

          For Example, add this in your xhtml:

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

          xmlns:rest="http://restfaces.dev.java.net"

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

          ....

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

          <rest:link value="viewCurrentTask">
                    <h:outputText value="#{taskBean.fullName}" />
                     <f:param name="taskId" value="#{taskBean.id}"/>                                           
          </rest:link>

           

           

          And add corresponding Rest Action method:

           

          /**
          * Action method called when user selects any task to view it.
          *
          * @return String for navigation purposes.
          */
          @HttpAction(value="viewCurrentTask", pattern="pages/taskView.jsf:taskId={taskId}")
          public String taskSelectedForView(@Param("taskId") Long taskId) {   
                  // some functional
                  return "/pages/taskView.xhtml";
          }

           

          For more info  https://restfaces.dev.java.net/docs-1.3/documentation.html

           

          Hope this will help.

          • 2. Re: Opening links in new tabs/windows problem
            frisch

            Hi,

             

            thanks for your tip. All links have actions or actionListeners and then I use faces.config to redirect the user to the proper page. I have a pretty big application and I have links on every page. Do you know of a easier way to achieve this withour replacing all links in my code with <rest:link> ?

             

             

            thanks

            • 3. Re: Opening links in new tabs/windows problem
              harut

              Hi,

                   Unfortunately I have no other solution for it. I had a same problem several months ago, and after all I found that Restfaces provides the best solution for it (besides that Restfaces provides very easy solutions for writing data initialization functionality when the page loads first time by writing "View Listener", most JSF developers do that in the Constructor of the Bean class which is not a good solution for that in my opinion...).

               

              Regards.