Filtering requestfactory response

49 views
Skip to first unread message

Thomas Lefort

unread,
Apr 6, 2012, 11:04:20 AM4/6/12
to google-we...@googlegroups.com
I have a user profile page and I want the server to send different
information when the user profile page is the one from the user and when
it's the one from another user.
I used to get my user profile information with rpc, so I just had to
send a DTO with some empty fields when it was another user.
I moved to request factory recently and I am trying to do the same type
of filtering. Is this possible? How can it be done?

Thanks,

Thomas

Thomas Broyer

unread,
Apr 6, 2012, 11:57:54 AM4/6/12
to google-we...@googlegroups.com
Same as you did previously: have your service return an object with some empty fields; simply replace RemoteServiceServlet#getThreadLocalRequest() with RequestFactoryServlet.getThreadLocalRequest() to get the current user.

Thomas Lefort

unread,
Apr 15, 2012, 6:02:28 AM4/15/12
to google-we...@googlegroups.com
Hi Thomas,

Thanks. I guess it makes sense ;-)

Another question if you don't mind... I am moving slowly with RF, I still like the RPC's simplicity and I already have many services implemented with RPC so the transition is difficult. I have set up a seperate project to test a bit the different scenarios and I quickly ran into problems when trying to create a new entity proxy and adding a list of other entity proxies to this entity. Basically, Employee has N Projects. I create an Employee client side and a few projects (for test sake) and add them to the user and attempt to save the whole graph at once. I do get user saved with the N projects hwoever all projects are empty, ie with default values, and I get a "Could not find static method with a single parameter of a key type" error message. The entities are persisted though as I said. I have the impression the issue is with persisting projects. I use JPA on the other side.
What got me is I couldn't find an equivalent example piece of code/project for this simple problem.

Here's a bit of code:

        EmployeeRequest request = requestFactory.employeeRequest();
        EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
        newEmployee.setDisplayName("Employee " + Math.random());
        newEmployee.setDepartment("Department " + Math.random());
        ProjectProxy project = requestFactory.projectRequest().create(ProjectProxy.class);
        project.setName("Project " + Math.random());
        newEmployee.setProjects(Arrays.asList(project));
        Request<Void> createReq = request.persist().using(newEmployee).with("projects");

If you have any clues ;-), highly appreciated.

Thanks,

Thomas

Thomas Broyer

unread,
Apr 15, 2012, 8:19:53 AM4/15/12
to google-we...@googlegroups.com
You have to use the same RequestContext to create all your proxies!

Thomas Lefort

unread,
Apr 16, 2012, 5:29:46 AM4/16/12
to google-we...@googlegroups.com
Ha! (I feel a bit stupid)

That does indeed solve the issue of the db update, however I still get the error message "Could not find static method with a single parameter of a key type". Will look into that a bit more.

Thanks again.

Thomas
Reply all
Reply to author
Forward
0 new messages