从 GWT 设置 html 字段?
我有一个 GWT 应用程序,需要从 java 代码(GWT)设置 html 字段 我尝试了这个,但元素始终为空
Element element = Document.get().getElementById("elementID");
if (element != null)
{
GWT.log("found element with id:" + "elementID");
// some code....
}
项目结构:
|---Main.html:加载编译模块的页面
|---page.html:需要从GWT更新的页面
所以我的问题是,是否可以设置来自 GWT 代码的 page.html 中的字段,如果是这样怎么办?
注意: page.html 在单击如下定义的锚点后显示:Anchor 锚点 = 新锚点( “信息”, 错误的, “页面.html”, “_blank”);
编辑: 页面.html:
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body style="font-size:62.5%;">
<div align="center" width="100%" height="80%">
<table height="80%" width="40%">
<tr valign="bottom">
<td align="center">
<div id="progressbar"></div>
</td>
<td><a id="cancel" href="#"><img src="close_icon_x.png" height="32px" width="32px"/></a></td>
</tr>
<tr><td valign="top"><div id ="elementID"></div>
</td><td></td></tr>
</table>
</div>
</body>
</html>
主.html:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript" src="project/MyProject.nocache.js"></script>
<link media="all" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"
type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
type="text/javascript" charset="utf-8"></script>
<link type="text/css" rel="stylesheet" href="Style.css">
</head>
-->
<body>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
</body>
</html>
I have a GWT application that need to set html field from java code(GWT)
i tried this but element is always null
Element element = Document.get().getElementById("elementID");
if (element != null)
{
GWT.log("found element with id:" + "elementID");
// some code....
}
Project structure:
|---Main.html: page that loads compiled module
|---page.html: the page that need to be updated from GWT
So my question, is it possible to set field in page.html from GWT code, if so how??
Note: page.html is show after clicking anchor defined like this:Anchor
anchor = new Anchor(
"message",
false,
"page.html",
"_blank");
EDIT:
Page.html:
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body style="font-size:62.5%;">
<div align="center" width="100%" height="80%">
<table height="80%" width="40%">
<tr valign="bottom">
<td align="center">
<div id="progressbar"></div>
</td>
<td><a id="cancel" href="#"><img src="close_icon_x.png" height="32px" width="32px"/></a></td>
</tr>
<tr><td valign="top"><div id ="elementID"></div>
</td><td></td></tr>
</table>
</div>
</body>
</html>
Main.html:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript" language="javascript" src="project/MyProject.nocache.js"></script>
<link media="all" type="text/css"
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"
type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js"
type="text/javascript" charset="utf-8"></script>
<link type="text/css" rel="stylesheet" href="Style.css">
</head>
-->
<body>
<noscript>
<div style="width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif">
Your web browser must have JavaScript enabled
in order for this application to display correctly.
</div>
</noscript>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为解决方案与这篇文章中的解决方案类似:
GWT:DOM.getElementById不起作用!
确实Riley是正确的,你在哪里定义 elementId ?
您可以设置该字段。问题的解决方案在于为什么你会得到一个空指针。
更新:您确定在调用 getElementID 之前已经渲染了实际的 page.html 代码,否则您将始终得到 Null。
I think the solution is similar to one in this post:
GWT: DOM.getElementById doesn't work!
Indeed Riley is correct, where did you define the elementId ?
You can set the field. The problem solution is in why you do get a null pointer.
UPDATE: Are you sure the actual page.html code has been rendered before the invocation of getElementID else you will always get Null.