GWT MVP and RequestFactory

561 views
Skip to first unread message

Nicholas

unread,
Nov 17, 2010, 3:06:01 PM11/17/10
to Google Web Toolkit
I am working on a small GWT app (I have used GWT in the past but it
was a while ago), trying to learn the new MVP and RequestFactory. I
am not sure if I am just approaching this wrong, or have some error I
can't spot. When I add a call to instantiate my app's RequestFactory,
it no longer runs. It gives me "Deferred Binding Failed" for my
request factory.

I went back and double-checked the domain / entity objects and I think
I have the required pattern in place (implicit no-arg constructor,
getId(), findEntity(id) and getVersion()).

Some of the relevant code:

Domain objects:
http://code.google.com/p/eatright/source/browse/#svn/trunk/EatRightApp/src/com/eatrightapp/server/domain

EntityRequest and Proxy objects:
http://code.google.com/p/eatright/source/browse/#svn/trunk/EatRightApp/src/com/eatrightapp/shared

This class instantiates the RequestFactory (line 35) and passes it to
the Activity (line 41)
http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src/com/eatrightapp/publicweb/client/mvp/AppActivityMapper.java

This class is where I have a method utilizing the request factory. (~
line 49)
http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src/com/eatrightapp/publicweb/client/activity/UserAccountsActivity.java

http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src/com/eatrightapp/admin/client/Admin.java

Any ideas?

Thomas Broyer

unread,
Nov 17, 2010, 7:28:46 PM11/17/10
to Google Web Toolkit


On 17 nov, 21:06, Nicholas <nick.sm...@gmail.com> wrote:
> I am working on a small GWT app (I have used GWT in the past but it
> was a while ago), trying to learn the new MVP and RequestFactory.  I
> am not sure if I am just approaching this wrong, or have some error I
> can't spot.  When I add a call to instantiate my app's RequestFactory,
> it no longer runs.  It gives me "Deferred Binding Failed" for my
> request factory.
>
> I went back and double-checked the domain / entity objects and I think
> I have the required pattern in place (implicit no-arg constructor,
> getId(), findEntity(id) and getVersion()).
>
> Some of the relevant code:
>
> Domain objects:http://code.google.com/p/eatright/source/browse/#svn/trunk/EatRightAp...
>
> EntityRequest and Proxy objects:http://code.google.com/p/eatright/source/browse/#svn/trunk/EatRightAp...
>
> This class instantiates the RequestFactory (line 35) and passes it to
> the Activity (line 41)http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src...
>
> This class is where I have a method utilizing the request factory. (~
> line 49)http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src...
>
> http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src...
>
> Any ideas?

Your "service methods" in your domain objects aren't static, but
aren't declared as InstanceRequest in your RequestContext.
(don't you have more specific errors than "deferred binding failed"?)

Nicholas

unread,
Nov 18, 2010, 12:05:19 PM11/18/10
to Google Web Toolkit
Thanks, you got me on the right rack. I didn't realize that more
information on the exceptions was available in the dev mode console of
eclipse. My domain entity objects had some Boolean accessors which I
had named isProperty() instead of getProperty(). I changed all of
those, and also made the domain service methods 'static' like you
suggested.

Now the application is running, but when it fires a request for
UserInformation, I get a null pointer exception. After debugging, it
gets into AbstractRequestContext.doFire(receiver) method, which
attempts to call requestFactory.getRequestTransport().send(...).
requestFactory.getRequestTransport() returns NULL so it throws a Null
Pointer Exception. Do I need to configure the transport somewhere? I
didn't see anything in the documentation or the Expenses sample app.

The portion of my code that is initiating this is (~ line 60) in:
http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src/com/eatrightapp/publicweb/client/activity/UserAccountsActivity.java

Richard Berger

unread,
Nov 18, 2010, 2:50:20 PM11/18/10
to Google Web Toolkit
I am having a very similar problem - NullPointerException when I call
fire() (the NPE is in AbstractRequestContext.doFire()). So I am
wondering if you have found a solution to your problem.

The code with the fire() is:
CommitmentSystemRequestFactory requestFactory =
GWT.create(CommitmentSystemRequestFactory.class);
requestFactory.commitmentRequest().countCommitments().fire(
new Receiver<Long>() {
@Override
public void onSuccess(Long response) {
Window.alert("Done!");
}
});

My CommitmentRequest class has:
@Service (Commitment.class)
public interface CommitmentRequest extends RequestContext {
Request<Long> countCommitments();

My Commitment.java class has:
public static long countCommitments() {
....
}

Some other notes...
* I have also been going through the Expenses sample app, both the
description at: http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html#proxies
and the sample code.
* I am NOT using JPA. My first learning project for GWT/GAE was with
JPA, but now I wanted to try the RequestFactory and then add
Objectify.
* I am NOT using MVP. I just don't yet have the critical mass of
brain cells necessary.

Thanks for any updates or advice...
RB

On Nov 18, 9:05 am, Nicholas <nick.sm...@gmail.com> wrote:
> Thanks, you got me on the right rack.  I didn't realize that more
> information on the exceptions was available in the dev mode console of
> eclipse.  My domain entity objects had some Boolean accessors which I
> had named isProperty() instead of getProperty().  I changed all of
> those, and also made the domain service methods 'static' like you
> suggested.
>
> Now the application is running, but when it fires a request for
> UserInformation, I get a null pointer exception.  After debugging, it
> gets into AbstractRequestContext.doFire(receiver) method, which
> attempts to call requestFactory.getRequestTransport().send(...).
> requestFactory.getRequestTransport() returns NULL so it throws a Null
> Pointer Exception.  Do I need to configure the transport somewhere?  I
> didn't see anything in the documentation or the Expenses sample app.
>
> The portion of my code that is initiating this is (~ line 60) in:http://code.google.com/p/eatright/source/browse/trunk/EatRightApp/src...

Richard Berger

unread,
Nov 18, 2010, 3:05:45 PM11/18/10
to Google Web Toolkit
As is typical - after working on this for hours, I think I found my
problem 10 minutes after posting. Since I am trying to avoid MVP (for
now, until the brain cell count improves), I had not initialized my
RequestFactory. Adding:
final EventBus eventBus = new SimpleEventBus();
requestFactory.initialize(eventBus);
has moved me past my NPE. Into other errors of course...

Thanks for listening....

RB

On Nov 18, 11:50 am, Richard Berger <richardlan...@gmail.com> wrote:
> I am having a very similar problem - NullPointerException when I call
> fire() (the NPE is in AbstractRequestContext.doFire()).  So I am
> wondering if you have found a solution to your problem.
>
> The code with the fire() is:
> CommitmentSystemRequestFactory requestFactory =
>         GWT.create(CommitmentSystemRequestFactory.class);
> requestFactory.commitmentRequest().countCommitments().fire(
>   new Receiver<Long>() {
>                 @Override
>                 public void onSuccess(Long response) {
>                         Window.alert("Done!");
>                 }
>   });
>
> My CommitmentRequest class has:
> @Service (Commitment.class)
> public interface CommitmentRequest extends RequestContext {
>   Request<Long> countCommitments();
>
> My Commitment.java class has:
>   public static long countCommitments() {
>     ....
>   }
>
> Some other notes...
> * I have also been going through the Expenses sample app, both the
> description at:http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.h...

Nicholas

unread,
Nov 18, 2010, 7:18:16 PM11/18/10
to Google Web Toolkit
Richard, I was missing that initialization to requestFactory as well.
I had to add that, and I had to add the following sections to my
web.xml:

<servlet>
<servlet-name>requestFactoryServlet</servlet-name>
<servlet-
class>com.google.gwt.requestfactory.server.RequestFactoryServlet</
servlet-class>
</servlet>

<servlet>
<servlet-name>remoteapi</servlet-name>
<servlet-
class>com.google.apphosting.utils.remoteapi.RemoteApiServlet</servlet-
class>
</servlet>

<servlet-mapping>
<servlet-name>remoteapi</servlet-name>
<url-pattern>/remote_api</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>requestFactoryServlet</servlet-name>
<url-pattern>/gwtRequest</url-pattern>
</servlet-mapping>


In addition, I added the appengine-tools-api.jar files to my web-inf/
lib folder.

I had to add the following to my apps gwt.xml file:

<inherits name='com.google.gwt.json.JSON'/>

Finally, I added json.jar to my web-inf/lib folder. I'm not sure
where this file originated, but I finally tracked down a copy at:
http://google-web-toolkit.googlecode.com/svn-history/r7687/trunk/bikeshed/war/WEB-INF/lib/json.jar


Now the app seems to be running without any errors. I think some of
this needs to go into the RequestBuilder/MVP documentation. If it's
there I completely overlooked it.

Nick

Nicholas

unread,
Nov 18, 2010, 7:57:18 PM11/18/10
to Google Web Toolkit
One more thing I forgot to mention. You have to add an init-param to
the requestFactoryServlet to identify your implementation class for
the user information class. (This is in your web.xml). Mine looks
like this.


<servlet>
<servlet-name>requestFactoryServlet</servlet-name>
<servlet-
class>com.google.gwt.requestfactory.server.RequestFactoryServlet</
servlet-class>
<init-param>
<param-name>userInfoClass</param-name>
<param-value>com.eatrightapp.server.domain.GaeUserInformation</
param-value>
</init-param>
</servlet>


Without that specified, your login widget will always show the user as
"Dummy User" and the logout link will not be functional. Now that all
this is in place, mine is completely working as expected.

Thanks,
Nick
> where this file originated, but I finally tracked down a copy at:http://google-web-toolkit.googlecode.com/svn-history/r7687/trunk/bike...

ali

unread,
Dec 4, 2010, 11:14:54 PM12/4/10
to Google Web Toolkit
I haven't seen any of this in the documentation either!

On Nov 18, 4:57 pm, Nicholas <nick.sm...@gmail.com> wrote:
> One more thing I forgot to mention.  You have to add an init-param to
> therequestFactoryServletto identify your implementation class for

ali

unread,
Dec 4, 2010, 11:41:36 PM12/4/10
to Google Web Toolkit
I am hitting the following error when using RequestFactory (it's about
ValidatorFactory impl not available). Does any one know why ?

20:32:35.092 [ERROR] [Skulgia] Uncaught exception escaped
java.lang.RuntimeException: Server Error 500 <html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1"/>
<title>Error 500 javax/validation/ValidatorFactory</title>
</head>
<body><h2>HTTP ERROR 500</h2>
<p>Problem accessing /Skulgia/gwtRequest. Reason:
<pre> javax/validation/ValidatorFactory</pre></p><h3>Caused by:</
h3><pre>java.lang.NoClassDefFoundError: javax/validation/
ValidatorFactory
at
com.google.gwt.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:
111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
58)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:
218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:
404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ClassNotFoundException:
javax.validation.ValidatorFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:
151)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 28 more
</pre>
<h3>Caused by:</h3><pre>java.lang.ClassNotFoundException:
javax.validation.ValidatorFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:
151)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
com.google.gwt.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:
111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
511)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1166)
at
com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:
58)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:
43)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:
122)
at org.mortbay.jetty.servlet.ServletHandler
$CachedChain.doFilter(ServletHandler.java:1157)
at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
388)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
182)
at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
765)
at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at
com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:
70)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at com.google.appengine.tools.development.JettyContainerService
$ApiProxyHandler.handle(JettyContainerService.java:349)
at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
542)
at org.mortbay.jetty.HttpConnection
$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:
218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:
404)
at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
409)
at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:582)
</pre>
<hr /><i><small>Powered by Jetty://</small></i><br/>
<br/>
<br/>
<br/>

Efstathios Kalyvas

unread,
Dec 19, 2010, 3:09:45 PM12/19/10
to google-we...@googlegroups.com
Hi, I have exactly the same error 
I cannot resolve it. 

I am using google eclipse plug in to create my project.
Google is not providing a simple working demo of RequestFactory (including all the jar references the web.xml etc).
They make things difficult for no reason.

So far I am using RPC to manipulate read/write/edit data.

Thanks
Savilak

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Thomas Broyer

unread,
Dec 19, 2010, 4:34:59 PM12/19/10
to google-we...@googlegroups.com


On Sunday, December 19, 2010 9:09:45 PM UTC+1, savilak wrote:
Google is not providing a simple working demo of RequestFactory (including all the jar references the web.xml etc).

The Expenses sample is using RequestFactory with Maven, it has the required dependencies on javax.validation and org.json, as well as a dependency on hibernate validator (as a javax.validation implementation).

The DynaTableRf sample is using RequestFactory (without Maven), it therefore uses gwt-servlet-deps.jar which contains both javax.validation and org.json.

Efstathios Kalyvas

unread,
Dec 19, 2010, 4:57:36 PM12/19/10
to google-we...@googlegroups.com
I found the solution here:


It says to do the following (in case you do not use maven):

"Otherwise, you can just add gwt-servlet- 
deps.jar to your WEB-INF/lib in addition to gwt-servlet.jar"

Google should be more careful with RequestFactory.
The samples they provide work with maven plus
they use JPA although so far I was under the impression they suggested JDO
(at least their appengine samples use JDO).
Why creating such a polyphony with their samples I do not get it?

Anyway...
Reply all
Reply to author
Forward
0 new messages