Search code examples
jsf-2java-ee-6myfaces

Navigate from one war to another JSF through bean


I have 3 wars in one EAR. Once user clicks on a link in a page, control goes to bean and business logic decides where user will be navigated. Resulting page can be in any of the three wars.

Also i need requesting URL so that I can navigate user back to requesting page if they decide to click on cancel link.

I can navigate using JSF by defining navigation in faces-config.xml e.g:

<from-view-id>/GeneralInfo.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{registrationBean.goToLogin}</from-action>
            <from-outcome>Success</from-outcome>
            <to-view-id>/LoginInfo.xhtml</to-view-id>
        </navigation-case>

But this navigation is limited for navigation between pages inside single war.

2nd option is using faces redirect which can redirect even on 3rd party server URL's e.g: FacesContext.getCurrentInstance().getExternalContext().redirect('login.xhtml')

Using 2nd option i cannot retrieve requesting URL using below code

FacesContext.getCurrentInstance().getExternalContext().getRequest().getRequestURL();

My question is, Is their any 3rd option where I can navigate to pages into another war(having JSF configuration's) and can also get requesting URL as well.

Let me know if anything else is required.

Thanks


Solution

  • You can't use JSF navigation cases to go to pages in a different application context. So sending a redirect is the only option. If you'd like to pass additional parameters along with the redirect, then pass them as request query string parameters:

    String from = request.getRequestURL().toString();
    externalContext.redirect("/othercontext/login.xhtml?from=" + URLEncoder.encode(from, "UTF-8"));
    

    The other application can then just redirect back as follows:

    String from = request.getParameter("from");
    externalContext.redirect(from);