Passing Parameters to GWT App

1,223 views
Skip to first unread message

al.h...@gmail.com

unread,
May 22, 2007, 7:07:47 AM5/22/07
to Google Web Toolkit
Hello All,

Hoping someone can help. I have built a simple GWT app and would like
to pass some parameters into the app depending on which HTML page I am
including the GWT app on. So for example below I have two pages that
call the same GWT app and on the first page I would like to pass one
value and on the other a different value.

Is this possible? Any direction on this would be great.

Cheers,
Alan.


- indexA.html
<html>
<head>
<title>Wrapper HTML for Slicr</title>
<meta name='gwt:module' content='my.gwt.app.MyApp'>
</head>
<body>
<script language="javascript" src="gwt.js"></script>
<iframe id="__gwt_historyFrame" style="width:0;height:0;border:
0"></iframe>
<h1>My App -A</h1>
<div id="slot1"></div>
</body>
</html>


- indexB.html
<html>
<head>
<title>Wrapper HTML for Slicr</title>
<meta name='gwt:module' content='my.gwt.app.MyApp'>
</head>
<body>
<script language="javascript" src="gwt.js"></script>
<iframe id="__gwt_historyFrame" style="width:0;height:0;border:
0"></iframe>
<h1>My App -B</h1>
<div id="slot1"></div>
</body>
</html>

Nikolas Everett

unread,
May 22, 2007, 8:49:21 AM5/22/07
to Google-We...@googlegroups.com
Options:

1.  Define some javascript variable in the page and snag it using jsni.
2.  Make a DOM node with some set ID and store the information in it like so:
<div class="config" id="something">foo</div>
<div class="config" id="e">bar</div>
I don't have it in front of my right now, but I think you can find them with something like DOM.getInnerHTML(DOM.getElementByID("something")).
3.  Use the GWT class to get the URL.
4.  Crawl the DOM looking for some distinguishing feature.

I've arranged them in my order of preference.  3 and 4 are only reserved for weird cases, but I have had to use them.

--Nik

ankostis

unread,
May 22, 2007, 9:39:02 AM5/22/07
to Google Web Toolkit
Hi,

Ensure that each host page contains a hidden div element with an id
and the arbitrary text value, like that:
<div id="page.params" style="visibility: hidden;" >Hello</div>

And then in your code, use something along these lines:
RootPanel params = RootPanel.get("page.params");
if (params != null) {
String value = Dom.getInnerText(params);
...
}

Regards,
Kostis

Rob Coops

unread,
May 22, 2007, 9:45:36 AM5/22/07
to Google-We...@googlegroups.com
Just a silly question but why a <div>? Why not use a <input type="hiden"> for this? as long as it is not part of a form it will not get submitted anywhere and it is in my opinion a nicer solution then just abusing a <div> tag for this.

 

Nikolas Everett

unread,
May 22, 2007, 10:05:11 AM5/22/07
to Google-We...@googlegroups.com
I haven't really thought about using a hidden <input> instead of a <div>.  I guess <div> just seemed an easier target for abuse.

--Nik

al.hicks

unread,
May 22, 2007, 11:00:08 AM5/22/07
to Google Web Toolkit
Thanks for the help.

Much appreciated.

:-D

On May 22, 3:05 pm, "Nikolas Everett" <nik9...@gmail.com> wrote:
> I haven't really thought about using a hidden <input> instead of a <div>. I
> guess <div> just seemed an easier target for abuse.
>
> --Nik
>
> On 22/05/07, Rob Coops <rco...@gmail.com> wrote:
>
>
>
> > Just a silly question but why a <div>? Why not use a <input type="hiden">
> > for this? as long as it is not part of a form it will not get submitted
> > anywhere and it is in my opinion a nicer solution then just abusing a <div>
> > tag for this.
>

Reinier Zwitserloot

unread,
May 22, 2007, 11:23:03 AM5/22/07
to Google Web Toolkit
Rob's idea also sounds good. I'd like to add one more option to the
already extensive list posted by Nikolas:

You can create your own meta tags and read those. e.g:

<meta name="myproject:config" content="something you parse with GWT">

you would parse this by using DOM.getElementsByTagName. Or if that
method doesn't exist, some JSNI magic (loop through each entity given
by document.getElementsByTagName("meta"))

On May 22, 3:45 pm, "Rob Coops" <rco...@gmail.com> wrote:
> Just a silly question but why a <div>? Why not use a <input type="hiden">
> for this? as long as it is not part of a form it will not get submitted
> anywhere and it is in my opinion a nicer solution then just abusing a <div>
> tag for this.
>

Nikolas Everett

unread,
May 22, 2007, 11:43:35 AM5/22/07
to Google-We...@googlegroups.com
Meta tags *feel* like the best place to have that sort of information.

rb

unread,
May 22, 2007, 12:25:08 PM5/22/07
to Google Web Toolkit
You can use the Dictionary class to pass values in from the HTML page.

ankostis

unread,
May 22, 2007, 1:31:47 PM5/22/07
to Google Web Toolkit
Actually i'm using a section with many parameters like that:
<div id="params" style="visible=hidden">
<div id="param1">Hello</div>
<div id="param2">World</div>
...
</div>

I choose it, because for me, it is more difficult to think of using
<input> elements outside <form> elements.
Anyway, i believe your are more appropriately to judge it, since i
have a more java-centric background.

Kostis

On May 22, 4:45 pm, "Rob Coops" <rco...@gmail.com> wrote:
> Just a silly question but why a <div>? Why not use a <input type="hiden">
> for this? as long as it is not part of a form it will not get submitted
> anywhere and it is in my opinion a nicer solution then just abusing a <div>
> tag for this.
>

charlie...@gmail.com

unread,
May 22, 2007, 1:48:57 PM5/22/07
to Google Web Toolkit
You can also use the Dictionary class, very handy (and can be used for
a lot more than just i18n):
http://code.google.com/webtoolkit/documentation/com.google.gwt.i18n.client.Dictionary.html.

On May 22, 7:07 am, "al.hi...@gmail.com" <al.hi...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages