1 Reply Latest reply on Oct 5, 2010 11:37 PM by sivaprasad9394

    jsf navigation from one outcome to diff viewId

    elenaveretilo

      Hi all! I need your help! I have a jsf app, which now have 2 versions - one for mobile and one for desktop browsers. The pages for desktop lie in folder /html, and for mobile - /html/mobile. I want one outcome decide what exactly pages to show - from /html or from /html/mobile.
      I create session attribute isMobileBrowser - which indicates what browser I have.

       

      Boolean isMobileBrowser = (Boolean) session.getAttribute("isMobileBrowser");
       if (isMobileBrowser == null) {
       Enumeration e = req.getHeaders("user-agent");
      while(e.hasMoreElements()) {
       String str = e.nextElement().toString().toLowerCase();
       if (str.indexOf("mobile") != -1) {
       isMobileBrowser = new Boolean(true);
       System.out.println("MOBILE BROWSER");
       } else {
       isMobileBrowser = new Boolean(false);
       System.out.println("STANDARD BROWSER");
       }
       session.setAttribute("isMobileBrowser", isMobileBrowser);
      }
      

       

      }

       

      And now I want somethin like that:

       

      <navigation-rule>
       <from-view-id>*</from-view-id>
       <navigation-case>
       <from-outcome>clientadmin</from-outcome>
       // if mobile
       <to-view-id>/html/mobile/clientadmin.jsf</to-view-id>
       // if desktop
       <to-view-id>/html/clientadmin.jsf</to-view-id>
       </navigation-case>
       </navigation-rule>
      

       

       

      How I can do it better. I find out NavigationHandler, but dont understand how it works. I also try with conditions in xml - but I dont think they work (I use jsf 2.0).

       

      Any help will be greate! Thanks!

        • 1. Re: jsf navigation from one outcome to diff viewId
          sivaprasad9394

          while returning from bean check if mobile means return like "mobileclientadmin" and suppose if it is desktop means return like "desktopclentadmin".

           

          public String urMethodName()//add ur method name as per ur wish

          {

          String action = null;

          Boolean isMobileBrowser = (Boolean) session.getAttribute("isMobileBrowser");

          if (isMobileBrowser == null) {

          Enumeration e = req.getHeaders("user-agent");

          while(e.hasMoreElements()) {

          String str = e.nextElement().toString().toLowerCase();

          if (str.indexOf("mobile") != -1) {

          isMobileBrowser = new Boolean(true);

          System.out.println("MOBILE BROWSER");

          action="mobileclientadmin";

          } else {

          isMobileBrowser = new Boolean(false);

          System.out.println("STANDARD BROWSER");

          action="desktopclentadmin";

          }

          session.setAttribute("isMobileBrowser", isMobileBrowser);

          }

          return action;

          }

           

           

          <navigation-rule>

          <from-view-id>*</from-view-id>

          <navigation-case>

          <from-outcome>mobileclientadmin</from-outcome>

          // if mobile

          <to-view-id>/html/mobile/clientadmin.jsf</to-view-id>

            </navigation-case>

            <navigation-case>

          <from-outcome>desktopclentadmin</from-outcome>

          // if desktop

          <to-view-id>/html/clientadmin.jsf</to-view-id>

          </navigation-case>

          </navigation-rule>

           

           

          public String urMethodName()//add ur method name as per ur wish
          {
          String action = null;
          Boolean isMobileBrowser = (Boolean) session.getAttribute("isMobileBrowser");
          if (isMobileBrowser == null) {
          Enumeration e = req.getHeaders("user-agent");
          while(e.hasMoreElements()) {
          String str = e.nextElement().toString().toLowerCase();
          if (str.indexOf("mobile") != -1) {
          isMobileBrowser = new Boolean(true);
          System.out.println("MOBILE BROWSER");
          action="mobileclientadmin";
          } else {
          isMobileBrowser = new Boolean(false);
          System.out.println("STANDARD BROWSER");
          action="desktopclentadmin";
          }
          session.setAttribute("isMobileBrowser", isMobileBrowser);
          }
          return action;
          }