0

Project structure:

root
 -WebContent
    -mobile
      -login.xhtml
    -desktop
      -login.xhtml

My web.xml will load desktop/login.xhtml onload which uses UserBean as a backing bean, In postconstruct of UserBean, I'm trying to redirect my login to mobile/login.xhtml if the renderkit is mobile. I'm doing this by the following code:

@PostConstruct
    public void myPostConstruct(){
        String renderKitId = FacesContext.getCurrentInstance().getViewRoot().getRenderKitId();        
        if(renderKitId.equalsIgnoreCase("PRIMEFACES_MOBILE")){
            try
            {

                FacesContext.getCurrentInstance().getExternalContext().redirect("/mobile/login.xhtml");
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

I'm confused with the absolute path to be given for redirect; I need to move from desktop/login.xhtml to mobile/login.xhtml; how do I do that?

FiendFyre
  • 157
  • 3
  • 17
  • have you tried with "~/mobile/login.xhtml" ? – Anton Belev Jul 12 '13 at 19:04
  • yup! not working. The resulting url is : "localhost:8080/desktop/~/mobile/login.xhtml" – FiendFyre Jul 12 '13 at 19:12
  • FacesContext.getCurrentInstance().getExternalContext().getContextName() this returns "root" which is correct! – FiendFyre Jul 12 '13 at 19:24
  • 1
    FacesContext.getCurrentInstance().getApplication().getNavigationHandler() .handleNavigation(FacesContext.getCurrentInstance(), "MOBILE", "/mobile/login.xhtml"); This solved my issue. Thank you! – FiendFyre Jul 12 '13 at 20:31

0 Answers0