我不太熟悉vaadin 7,我無法弄清楚這一點。我試圖使用谷歌,但沒有有用的結果。vaadin 7網址參數
我的問題很簡單。我如何在我的UI類中獲取請求url參數?
我的網址有一個參數:host/myvaadinapp/?code=erefdvdfgftf...
url參數來自Facebook的用戶登錄(OAuth的)後,我需要處理在我的代碼代碼的URL參數的值。
我試過做這些:
@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"));
...
}
}
結果: request.getAttribute( 「代碼」):空 的request.getParameter( 「代碼」):空
我意識到getParameterMap( )有一個「v-loc」參數。但是,如果使用它的變量我必須寫一些代碼從這個變量獲取URL參數:
V-LOC:host/myvaadinapp/?code=erefdvdfgftf...
主題:馴鹿 V-rtzo:-600 V-dston:假 ...
我想,這不是太好的解決方案。
你能幫助我如何獲得vaadin中的原始URL參數?
謝謝。
我的評論是:
我試圖用的request.getParameter( 「代碼」),但它不工作。我不知道爲什麼。
我原來的網址是:host/demoVaadinApp/?name=zzz
我用這個代碼:
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));
}
}
我開始嵌入UI模式我vaadin應用。我的web.xml文件的
內容:
<!-- ******************************************************************* -->
<!-- context parameters -->
<!-- ******************************************************************* -->
<context-param>
<description>Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<!-- ******************************************************************* -->
<!-- servlet definition -->
<!-- ******************************************************************* -->
<!-- +++++ Vaadin servlet +++++++++++++++++++++++++++++++++++++++++++++ -->
<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 definition -->
<!-- ******************************************************************* -->
<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">
<!-- Optional placeholder for the loading indicator -->
<div class=" v-app-loading"></div>
<!-- Alternative fallback text -->
<noscript>You have to enable javascript in your browser to use this application.</noscript>
</div>
<!-- Initializing the UI -->
<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>
我的結果是: 你好未知。
如果我不使用嵌入式UI模式比一切工作得很好。
問題在哪裏?
解決方案(感謝您對雷夫Åstrand):
VAR urlParts = window.location.href.split( 「?」);
var queryString =(urlParts.length == 1)? 「」:「?」 + urlParts [1];
queryString =(urlParts.length == 0)? 「」:queryString.split(「#」)[0];
和
「browserDetailsUrl」: 「VAADIN」 +的queryString,
完整的源代碼:
<!-- Initializing the UI -->
<script type="text/javascript">
var urlParts = window.location.href.split("?");
var queryString = (urlParts.length == 1) ? "" : "?" + urlParts[1];
queryString = (urlParts.length == 0) ? "" : queryString.split("#")[0];
//<![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",
...
謝謝你的回答! 我解決了它,並在上面分享了我的解決方案。 – zappee 2013-05-15 12:31:11