0

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.

KidTempo
  • 910
  • 1
  • 6
  • 22
  • did u try absolute url - http://www.abc.com/app2/pageA ? – sanbhat May 17 '13 at 17:03
  • yes, I edited my question a little too slowly - that's not appropriate in my case because the host name changes depending on which machine my app is deployed on – KidTempo May 17 '13 at 17:05

2 Answers2

2

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>
Jitesh
  • 1,384
  • 10
  • 20
1

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.

Community
  • 1
  • 1
Leo
  • 1,829
  • 4
  • 27
  • 51