title: vaadin 7 URL parameter
body: <p>I am not too familiar with vaadin 7 and I can not figure out this. I tried to use google but no useful result.</p>
  
  <p>My question is very simple. How can I get the request url parameters in my UI class?</p>
  
  <p>My url has a parameter: <code>host/myvaadinapp/?code=erefdvdfgftf...</code></p>
  
  <p>The url parameter comes from facebook after user logged in (OAuth) and I need to handle the value of code url parameter in my code.</p>
  
  <p>I tried to do these:</p>
  
  <pre><code>    @PreserveOnRefresh
      public class AdminUi extends UI
      {
          @Override
          protected void init(VaadinRequest request)
          {
              ...
              System.out.println( request.getPathInfo());
              System.out.println( request.getRemoteHost());
              System.out.println( request.getParameterMap().size());
              System.out.println( request.getAttribute("code") );
              System.out.println( request.getParameter("code") );
              ...
          }
      }
  </code></pre>
  
  <p>Result:
  request.getAttribute("code"): null
  request.getParameter("code"): null</p>
  
  <p>I realized that getParameterMap() has a "v-loc" parameter. But if I use it variable I have to write some code to get url parameter from this variable: </p>
  
  <p>v-loc: <code>host/myvaadinapp/?code=erefdvdfgftf...</code>
  theme: reindeer
  v-rtzo: -600
  v-dston: false
  ...</p>
  
  <p>I think, it is not too nice solution.</p>
  
  <p>Could you help me how can I get the original url parameters in vaadin?</p>
  
  <p>Thank you.</p>
  
  <hr>
  
  <p>My comment are:</p>
  
  <p>I tried to use request.getParameter("code") but it was not working. I do not know why.</p>
  
  <p>My original url was: <code>host/demoVaadinApp/?name=zzz</code></p>
  
  <p>I used this code:</p>
  
  <pre><code>    public class Xxxx extends UI
      {
          /**
       * Main UI
       */
      @Override
      protected void init(VaadinRequest request)
      {
          String name = request.getParameter("name");
          if (name == null)
              {
              name = "Unknown";
          }
  
          setContent(new Label("Hello " + name));
          }
      }
  </code></pre>
  
  <p>I start my vaadin application in Embedding UI mode.</p>
  
  <p>Content of my web.xml file:</p>
  
  <pre><code>&lt;!-- ******************************************************************* --&gt;
  &lt;!-- context parameters                                                  --&gt;
  &lt;!-- ******************************************************************* --&gt;
  &lt;context-param&gt;
      &lt;description&gt;Vaadin production mode&lt;/description&gt;
      &lt;param-name&gt;productionMode&lt;/param-name&gt;
      &lt;param-value&gt;false&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- ******************************************************************* --&gt;
  &lt;!-- servlet definition                                                  --&gt;
  &lt;!-- ******************************************************************* --&gt;
  &lt;!-- +++++ Vaadin  servlet +++++++++++++++++++++++++++++++++++++++++++++ --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;VaadinServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.vaadin.server.VaadinServlet&lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;description&gt;Vaadin UI class&lt;/description&gt;
          &lt;param-name&gt;UI&lt;/param-name&gt;
          &lt;param-value&gt;com.coupoholics.ui.admin.AdminUi&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;VaadinServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/VAADIN/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;!-- ******************************************************************* --&gt;
  &lt;!-- welcome file list definition                                        --&gt;
  &lt;!-- ******************************************************************* --&gt;
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  </code></pre>
  
  <p>index.html:</p>
  
  <p>
  </p>
  
  <pre><code>&lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;script type="text/javascript" src="./VAADIN/vaadinBootstrap.js"&gt;&lt;/script&gt;
      &lt;iframe tabindex="-1" id="__gwt_historyFrame" style="position: absolute; width: 0; height: 0; border: 0; overflow: hidden" src="javascript:false"&gt;&lt;/iframe&gt;
  
                   &lt;div id="content-body"&gt;
                      &lt;!-- Optional placeholder for the loading indicator --&gt;
                      &lt;div class=" v-app-loading"&gt;&lt;/div&gt;
                      &lt;!-- Alternative fallback text --&gt;
                      &lt;noscript&gt;You have to enable javascript in your browser to use this application.&lt;/noscript&gt;
                  &lt;/div&gt;
  
      &lt;!--  Initializing the UI --&gt;
      &lt;script type="text/javascript"&gt;
          //&lt;![CDATA[
              if (!window.vaadin)
                  alert("Failed to load the bootstrap JavaScript:" + "VAADIN/vaadinBootstrap.js");
  
              /* The UI Configuration */
              vaadin.initApplication("content-body", {
                "browserDetailsUrl": "VAADIN",
                "serviceUrl": "VAADIN",
                "widgetset": "com.vaadin.DefaultWidgetSet",
                "theme": "reindeer",
                "versionInfo": {"vaadinVersion": "7.0.5"},
                "vaadinDir": "VAADIN/",
                "heartbeatInterval": 300,
                "debug": true,
                "standalone": false,
                "authErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and &lt;u&gt;click here&lt;\/u&gt; to continue.",
                    "caption": "Authentication problem"
                },
                "comErrMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and &lt;u&gt;click here&lt;\/u&gt; to continue.",
                    "caption": "Communication problem"
                },
                "sessExpMsg": {
                    "message": "Take note of any unsaved data, "+
                               "and &lt;u&gt;click here&lt;\/u&gt; to continue.",
                    "caption": "Session Expired"
                }
           });//]]&gt;
          &lt;/script&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>My result is:
  Hello Unknown.</p>
  
  <p>If I do not use Embedding UI mode than everything is working very well.</p>
  
  <p>Where is the problem?</p>
  
  <hr>
  
  <p><em>The solution (thank you for Leif Åstrand):</em></p>
  
  <p><strong>var urlParts = window.location.href.split("?");</strong></p>
  
  <p><strong>var queryString = (urlParts.length == 1) ? "" : "?" + urlParts[1];</strong></p>
  
  <p><strong>queryString = (urlParts.length == 0) ? "" : queryString.split("#")[0];</strong></p>
  
  <p>and</p>
  
  <p><strong>"browserDetailsUrl": "VAADIN" + queryString,</strong></p>
  
  <p>Full source code:</p>
  
  <pre><code>    &lt;!--  Initializing the UI --&gt;
      &lt;script type="text/javascript"&gt;
          var urlParts = window.location.href.split("?");
          var queryString = (urlParts.length == 1) ? "" : "?" + urlParts[1];
          queryString = (urlParts.length == 0) ? "" : queryString.split("#")[0];
  
          //&lt;![CDATA[
              if (!window.vaadin)
                  alert("Failed to load the bootstrap JavaScript:" + "VAADIN/vaadinBootstrap.js");
  
              /* The UI Configuration */
              vaadin.initApplication("content-body", {
                "browserDetailsUrl": "VAADIN" + queryString,
                "serviceUrl": "VAADIN",
                            ...
  </code></pre>