I am not very familiar with vaadin 7, and I cannot figure it out. I tried using google, but not a useful result.
My question is very simple. How can I get request url parameters in my user interface class?
My url has a parameter: host/myvaadinapp/?code=erefdvdfgftf...
The url parameter comes from facebook after user login (OAuth), and I need to handle the value of the url parameter of the code in my code.
I tried to do this:
@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") ); ... } }
Result: request.getAttribute ("code"): null request.getParameter ("code"): null
I realized that getParameterMap () has a parameter of "v-loc". But if I use a variable, I need to write some code to get the url parameter from this variable:
v-loc: host/myvaadinapp/?code=erefdvdfgftf... topic: reindeer v-rtzo: -600 v-dston: false ...
I think this is not a very pleasant solution.
Could you help me, how can I get the url source parameters in vaadin?
Thanks.
My comments:
I tried using request.getParameter ("code"), but it did not work. I do not know why.
My original url was: host/demoVaadinApp/?name=zzz
I used this code:
public class Xxxx extends UI { @Override protected void init(VaadinRequest request) { String name = request.getParameter("name"); if (name == null) { name = "Unknown"; } setContent(new Label("Hello " + name)); } }
I run my vaadin app in UI attachment mode.
The contents of my web.xml file:
<context-param> <description>Vaadin production mode</description> <param-name>productionMode</param-name> <param-value>false</param-value> </context-param> <servlet> <servlet-name>VaadinServlet</servlet-name> <servlet-class>com.vaadin.server.VaadinServlet</servlet-class> <init-param> <description>Vaadin UI class</description> <param-name>UI</param-name> <param-value>com.coupoholics.ui.admin.AdminUi</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>VaadinServlet</servlet-name> <url-pattern>/VAADIN/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>
index.html
<head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <script type="text/javascript" src="./VAADIN/vaadinBootstrap.js"></script> <iframe tabindex="-1" id="__gwt_historyFrame" style="position: absolute; width: 0; height: 0; border: 0; overflow: hidden" src="javascript:false"></iframe> <div id="content-body"> <div class=" v-app-loading"></div> <noscript>You have to enable javascript in your browser to use this application.</noscript> </div> <script type="text/javascript"> //<![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 <u>click here<\/u> to continue.", "caption": "Authentication problem" }, "comErrMsg": { "message": "Take note of any unsaved data, "+ "and <u>click here<\/u> to continue.", "caption": "Communication problem" }, "sessExpMsg": { "message": "Take note of any unsaved data, "+ "and <u>click here<\/u> to continue.", "caption": "Session Expired" } });//]]> </script> </body>
My result: Hello Unknown.
If I do not use Embedding UI mode, everything works very well.
Where is the problem?
Solution (thank you for Leif Åstrand):
var urlParts = window.location.href.split ("?");
var queryString = (urlParts.length == 1)? "": "?" + urlParts [1];
queryString = (urlParts.length == 0)? ": queryString.split (" # ") [0];
and
"browserDetailsUrl": "VAADIN" + queryString,
Full source code:
<script type="text/javascript"> var urlParts = window.location.href.split("?"); var queryString = (urlParts.length == 1) ? "" : "?" + urlParts[1]; queryString = (urlParts.length == 0) ? "" : queryString.split("#")[0];