KidTempo
KidTempo

Reputation: 930

How do you navigate between two web apps?

If I have two web apps http://www.abc.com/app1 and http://www.abc.com/app2 how do I handle navigation between the two?

I would like to be able to navigate to app2 using links in a menu that I have in a sidebar...

<p:menu>  
  <p:menuitem outcome="/index" value="Home" icon="ui-icon-home"/>  
  <p:submenu label="app1">
    <p:menuitem outcome="/page1" value="page1" />  
    <p:menuitem outcome="/page2" value="page2" />  
  </p:submenu>  
  <p:submenu label="app2">
    <!-- all the links below should point to pages in app2 -->
    <p:menuitem outcome="/pageA" value="pageA" />  
    <p:menuitem outcome="/pageB" value="pageB" />  
  </p:submenu>  
</p:menu>

Obviously outcome="/pageA" doesn't work because it tries to find a page with that name in app1 resulting in a 404. I have tried outcome="/app2/pageA" and outcome="../app2/pageA" but neither of those work. What are some other alternatives?

Also, I should add that I don't really want to hard-code the url "http://www.abc.com/app2/pageA" because the host name will change depending on where I do my deployment.

Upvotes: 0

Views: 128

Answers (2)

Jitesh
Jitesh

Reputation: 1382

You can achieve it by doing following,

Managed Bean:

@ManagedBean  
@ViewScoped
public class YourBean implements Serializable{

String project_path;

public String getProject_path() {
    return project_path;
}

public void setProject_path(String project_path) {
    this.project_path = project_path;
}

@PostConstruct
public void init() {
    HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    project_path = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
}

public YourBean() {
}
}

xhtml:

       <p:menu>
            <p:menuitem outcome="/index" value="Home" icon="ui-icon-home"/>  
            <p:submenu label="app1">
                <p:menuitem url="#{yourBean.project_path}/app1/page1" value="Page1"/>  
                <p:menuitem url="#{yourBean.project_path}/app1/page2" value="Page2"/>  
            </p:submenu>  
            <p:submenu label="app2">
                <p:menuitem url="#{yourBean.project_path}/app1/pageA" value="PageA"/>  
                <p:menuitem url="#{yourBean.project_path}/app1/pageA" value="PageA"/>   
            </p:submenu>  
        </p:menu>

Upvotes: 2

Leo
Leo

Reputation: 1919

you may get the host name in runtime ( for example this answer ), store it in a managed bean or something, so you won't hardcode the URL, this would work only if both applications are under the same hostname.

Upvotes: 1

Related Questions