8 Replies Latest reply on Jan 7, 2011 4:07 PM by mkiel

    Help about forwarding page

    ismaximum

      Hi


      In my application, when user clicks on some links, I want to invoke an action manually and forward it to another page. Could you help me how to manage it using pages.xml?


      I already wrote a filter in order to find those certain links and forward it to a specific URI and a Phase Listener in which I invoke the action manually when that specific URI is received but the problem is that after executing the action, the page won't be forwarded to the index.xhtml that I want to.


      Is there any solution  in Seam in order to say to invoke the action automatically in such situation?

        • 1. Re: Help about forwarding page
          vata2999

          Hi,
          What kind of link is that ? anyway try this in your page.xml




          
          <navigation from-action="#{yourActionMethod}">
                <rule if-outcome="theString return from your Action method">
                   <end-conversation/>
                   <redirect view-id="/index.xhtml"/>
                </rule>
             </navigation>



          and this is command fire action



          <s:link value="go to index.xhtml" action="#{yourActionMethod}" />







          • 2. Re: Help about forwarding page
            ismaximum

            Thanks for your reply.
            This doesn't help me. The links I stated are pure HTML and not from my application!


            Actually in my application I display the content of other applications (something like a portal but it's not a portal) so the page is displayed is not my page and I am not aware of its content!


            I have a Servlet filter to detect these external links and serve them through my actions.

            • 3. Re: Help about forwarding page
              mkiel

              Mohammad, have you tried page actions?

              • 4. Re: Help about forwarding page
                ismaximum

                Marcel, it seems it is the solution but could you please read my scenario:


                I have a plain html in which there is a link and the path of the link doesn't exist in my web application:


                • 5. Re: Help about forwarding page
                  mkiel

                  Ah, so you mean the page that the link refers to doesn't exist in your application. According to the docs, that should work, too:



                  Furthermore, the view id mentioned in the <page> element need not correspond to a real JSP or Facelets page!
                  • 6. Re: Help about forwarding page
                    ismaximum
                    Sorry Marcel, this Seam-text confused me!! the last reply was incomplete

                    Marcel, it seems it is the solution but could you please read my scenario as follow

                    I have a plain html in which there is a link and the path of the link doesn't exist in my web application\:

                    <a href=xpage/someStrutsAction?q=value1 > LINK </a>

                    "xpage" and the action is not my application but since I am displaying that page, it is apeared in content.

                    Now user clicks on that link, I have a Servlet filter that identifies this is not a link from my web app so I need to forward page to index.xhtml and execute an action. this action will serve the above link and populate the page with another plain html content.

                    currently in my filter I put this code:
                    req.getRequestDispatcher("/pages/process.ng").forward(req,res);

                    Do you think this will invoke the pages.xml?

                    "process.ng" is not a real path, I set it to distinguish that it is from an external link.

                    Currently my pages.xml is something like this:



                    '

                      < page view-id="/pages/process.ng" >
                             <action execute="#{dispatcher.dispatch}" />
                            <navigation><redirect view-id="/pages/index.ng" /></navigation>
                    </ page>

                    '
                    But it doesn't work. I want when target page is /pages/process.ng it executes the dispatch action and navigate to /pages/index.ng





                    <blockquote>
                    _Marcel Kiel wrote on Jan 04, 2011 17:02:_<br/>

                    Mohammad, have you tried [page actions=>http://docs.jboss.org/seam/2.2.1.CR3/reference/en-US/html/events.html#d0e4955]?
                    </blockquote>

                    • 7. Re: Help about forwarding page
                      ismaximum
                      It seems the pages.xml cannot understand forward() method from my filter. So I think I need to write a PhaseListener.

                      In this listener I invoke the action manually but the page wont be navigated to pages/index.ng

                      Now my listener is as follow:

                           public void beforePhase(PhaseEvent event) {
                                PhaseId pid = event.getPhaseId();
                                fc = event.getFacesContext();
                                HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
                                Boolean isExternalLink = (Boolean) request.getAttribute(IS_EXTERNAL_LINK);
                                if(isExternalLink == null) {
                                     isExternalLink = false;
                                }
                                if(isExternalLink && PhaseId.RESTORE_VIEW.equals(pid)) {
                                     String contextPath = request.getContextPath();
                                     String servletPath = request.getServletPath();
                                     if(servletPath.contains("process.ng")) {
                                          try {
                                               handleExternalLink(servletPath);
                                          } catch (IOException e) {
                                               e.printStackTrace();
                                          } catch (ServletException e) {
                                               e.printStackTrace();
                                          }
                                     }
                                     
                                     
                                }
                                
                           }

                           protected void handleExternalLink(String path) throws  IOException, ServletException {
                                String externalPath = path.substring(6); //this removes '/pages' from the path
                                
                                UIViewRoot view = fc.getApplication().getViewHandler().
                                createView(fc,"/pages/process.nextgen");
                                view.setViewId("/pages/process.nextgen");
                                fc.setViewRoot(view);
                                //fc.getApplication().getNavigationHandler().handleNavigation(fc,"dispatcher.dispatch","/pages/index.xhtml");
                                invokeMethodExpression("#{dispatcher.dispatch}",String.class,new Class[] {},new Object[] {});
                           }

                           private Object invokeMethodExpression(String expr, Class returnType, Class[] argTypes,Object[] args){
                                FacesContext fc = FacesContext.getCurrentInstance();
                                ELContext elctx  = fc.getELContext();
                                ExpressionFactory elFactory = fc.getApplication().getExpressionFactory();
                                MethodExpression methodExpr = elFactory.createMethodExpression(elctx,expr,returnType,argTypes);
                                return methodExpr.invoke(elctx,args);
                           }
                           public Object invokeMethodExpression(String expr, Class returnType,Class argType, Object argument){
                                return invokeMethodExpression(expr, returnType,new Class[]{argType}, new Object[]{argument});
                           }
                      • 8. Re: Help about forwarding page
                        mkiel

                        Could you also redirect manually from the the phase listener, just as you manually invoke the method, for example by using the component org.jboss.seam.faces.redirect? Or add the redirect to the called method.