Calling other servlets (beside RPC service) from GWT client code

959 views
Skip to first unread message

marsh...@gmail.com

unread,
Aug 9, 2006, 1:32:50 PM8/9/06
to Google Web Toolkit
I've got a client that makes an RPC call.
It then processes the result (an AttemptFeedback object). If the
object has an isDone flag set to true, I want to call a master servlet
that will generate a new page. Its not working. The master servlet is
not getting called after the RPC. Any ideas about what I did wrong or
better (cleaner) ways to get this effect?

Heres what I'm doing (code below). The HTML contains a <form> with my
MasterServlet as the action. The form has some hidden inputs which I
use the GWT DOM object set values in. I then use a JSNI function to
submit this form when the RPC returns isDone.

In web mode I can see that the RPC succeeds and returns isDone=true but
the call to MasterServlet doesn't happen.

In hosted mode I get errors like:
[ERROR] No JavaScript body found for native method 'private native void
submitToControlServlet()' in type 'class
edu.umass.ckc.wogwt.client.WoGWTProb'
- I'm thinking hosted mode is of less utility in debugging a
servlet-generated GWT HTML page but I try to keep it going for testing
sake.

Thanks,

dave

HTML (as generated by a MasterServlet) contains:

<script language="javascript">
sessionId=56; // *
</script>
.
.a GWT button widget for a submit button
.
<form name="myform" method="post" action="MasterServlet" >
<input id="sessionIDParam" type="hidden" name="sessID"
value="56"> <!-- GWT client will set value to correct sessionID -->
<input id="actionParam" type="hidden" name="action"
value="done"> <!-- GWT client will set value to correct action -->
</form>


My GWT client code

// this code is supposed to call the MasterServlet but doesn't
private native void submitToControlServlet () /*{
$doc.myform.submit();
}-*/;

private native int getSessionId () /*-{
return $wnd.sessionId;
}-*/;

My GWT submit button then has this ClickListener code

// when submit button clicked make RPC call, if isDone() is true set
attributes in the hidden input fields of the form named "myform" and
then use the JSNI
submitToControlServlet function to submit the form.
public void onClick(Widget sender) {
service.problemAttempted(new AsyncCallback() {
public void onSuccess(Object result) {
AttemptFeedback f = (AttemptFeedback) result;
if (f.isDone()) {
// submit a form to Master servlet and pass it
?sessionId=int&action=done
// this will return a new HTML page

DOM.setAttribute((Element)DOM.getElementById("sessionIDParam"),
getSessionId());

DOM.setAttribute((Element)DOM.getElementById("actionParam"),
"value","done");
submitToControlServlet();

ash

unread,
Aug 9, 2006, 6:52:04 PM8/9/06
to Google Web Toolkit
gday dave,

i read your post 3 times trying to figure out what your _real_
requirement is rather than your symptom. unfortunately, i do not have
enough context to determine that so im going to make some assumptions:
scenario 1
# u need to post information to a servlet
# you intend to remain the in the same GWT entry point instance

my recommendation:
use com.google.gwt.user.client.HTTPRequest.asyncPost();

scenario2:
# u need to post information to a servlet
# you intend to change the GWT entry point instance and reload a new
module

my recommendation:
use a framework that supports multiple entry points. In gems you do
some like the following:

1. from http://juls.googlecode.com/svn/trunk/webapp/WEB-INF/web.xml
...
<servlet>
<servlet-name>GemEntryPointPager</servlet-name>
<servlet-class>org.javaongems.server.GemEntryPointPager</servlet-class>
<init-param>
<param-name>gwt:entry-point-page</param-name>
<param-value>/jsps/layout.jsp</param-value>
</init-param>
<init-param>
<param-name>gwt:module</param-name>
<param-value>au.com.gworks.jump.app.wiki.Main</param-value>
</init-param>
<init-param>
<param-name>context.factory.resolver</param-name>

<param-value>org.javaongems.server.KeyedRequestParamFactoryResolver</param-value>
</init-param>
<init-param>
<param-name>context.factories</param-name>
<param-value>
explore=au.com.gworks.jump.app.wiki.server.mockimpl.WikiUrlExplorerPageFactory

default=au.com.gworks.jump.app.wiki.server.mockimpl.WikiUrlContentPageFactory
</param-value>
</init-param>
</servlet>

...

<servlet-mapping>
<servlet-name>GemEntryPointPager</servlet-name>
<url-pattern>/wiki/*</url-pattern>
</servlet-mapping>

this enable you to have dynamic entry points for a gwt application

---
i hope this helps. its very difficult to tell what your real goal is.

rgds ash
http://www.gworks.com.au/

self help sources:
1. http://javaongems.org/ -> http://code.google.com/p/javaongems/
2. http://code.google.com/p/gems-gwt-user/
3. http://code.google.com/p/juls/

marsh...@gmail.com

unread,
Aug 9, 2006, 7:24:49 PM8/9/06
to Google Web Toolkit
Sorry I muddled the post.

Lets try again based on your scenarios.I think I'm closert to scenario
2 but perhaps a little simpler. Heres a second try at explaining my
goal.

MasterServlet is called at the very beginning and it generates an HTML
page which is a GWT entry point. The page has a GWT Button called
submit. When submit is clicked, an RPC method is called. ( Note the
RPC is not defined as part of MasterServlet) This method returns an
object which is tested for the condition "isDone". If isDone is true,
then I want to call the MasterServlet with some params so it can
generate a new HTML page. This new HTML page is not necessarily
another entry point.

ash

unread,
Aug 9, 2006, 8:01:23 PM8/9/06
to Google Web Toolkit
> Sorry I muddled the post.
no worries.


> object which is tested for the condition "isDone". If isDone is true,
> then I want to call the MasterServlet with some params so it can
> generate a new HTML page. This new HTML page is not necessarily
> another entry point.

why not just call the MasterServlet with some parameters using a http
GET with a query string?

im my juls example i emulate MS::Windows Explorer. If the user double
clicks on a document then i want the system to transition them to that
document. I do this via GET not POST.

1.
http://juls.googlecode.com/svn/trunk/src/au/com/gworks/jump/app/wiki/client/navigation/ExplorerController.java
public void onDblClick(ListView vw, int dataRow, int col) {
String[] storeFolder = new String[1];
WikiRpc.ResourceAttrInfo[] storeRes = new
WikiRpc.ResourceAttrInfo[1];
boolean resType = getFolderResourceRowMapper(dataRow, storeFolder,
storeRes);
String newPath = (resType ? storeRes[0].getAbsolutePath():
storeFolder[0]);
if (resType)
Gem.stone.openParameterisedUrl(new String[] {namespace,
revSpecifier, newPath});
else {
moveToFolder(PathUtils.appendSlashIfRequired(folderPath) + newPath);
}
}

this will then ultimately invoke the following:
http://javaongems.googlecode.com/svn/trunk/src/org/javaongems/client/Gem.java

native public void openUrl(String url) /*-{
$wnd.location.href = url;
}-*/;

dave, you should only you the "post" approach as a last resort.

does this help?

marsh...@gmail.com

unread,
Aug 9, 2006, 10:30:56 PM8/9/06
to Google Web Toolkit
ash:

You got here before I did. Was just going to post my humiliating
admission of
having forgot that to load a new URL all you have to do is set
window.location.href = URL

Thats the problem with GWT. One forgets how to use basic Javascript!!!
Never mind the advanced AJAX stuff which is long forgotten.

I hope these google guys are serious about maintaining GWT because I'm
totally hooked (dependent).

br...@google.com

unread,
Aug 13, 2006, 7:30:21 PM8/13/06
to Google Web Toolkit
marsh...@gmail.com wrote:
> I hope these google guys are serious about maintaining GWT because I'm
> totally hooked (dependent).

We are.

-- Bruce

Reply all
Reply to author
Forward
0 new messages