0

In an existing application (JSF) I would like to replace a widget with a one implemented in GWT. I also want to reuse existing logic implemented in managed beans. Logic on the server needs more then just data from the widget to work (so it needs everything what is being submitted by the user's action) - I cannot just use GWT-RPC or similar mechanism (because I won't get JSF data).

The question is: how to pass data from GWT to the server so that I can access (on the server) java objects after they were edited by the GWT widget in the same place where submitted JSF action is handled?

EDIT:

Imagine that there is huge form generated by JSF, and a small, fancy map with position picker written in GWT. When the user clicks 'submit' I want to generate some data (on the server) based both on the form and the map - I need form content and position from the map at the same time in the same method. And the question is - how to achieve that? (it is just an example, the GWT widget is much more complex then a simple position picker)

mabn
  • 2,473
  • 1
  • 26
  • 47

2 Answers2

0

You can use RequestBuilder to call the server side logic from your GWT client code. If the server side has a RESTful endpoint it should be relatively easy. If the backend is written using SLSB, I would consider some intermediate layer on the server side (communicating with GWT), because afaik, the session beans are impossible (or close to imposible) to call directly from JavaScript.

Jiri Kremser
  • 12,471
  • 7
  • 45
  • 72
  • This way I will pass data from GWT, but not from the rest of the page. Imagine that there is huge form generated by JSF, and a small, fancy map with position picker written in GWT. When the user clicks 'submit' I want to generate some data (on the server) based both on the form and the map - I need form content and position from the map at the same time in the same method. And the question is - how to achieve that? (it is just an example, the GWT widget is much more complex then a simple position picker) – mabn Sep 21 '12 at 21:45
0

I assume you're submitting an HTML form (if not, please explain how you're currently transmitting data to the server)?

If yes, then you could add a hidden input element to your existing form, and let the GWT widget change the value of that hidden element whenever the widget's state changes (e.g. in a ClickHandler).

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • Yes, I'm submitting a form (sometimes using richfaces' ajax). So, you're proposing to serialize java objects to input element and later deserialize them on the server? (because the value to pass to the server won't be just a string, it will be a graph of many objects). If so - which serialization technique for GWT should be used here? – mabn Sep 22 '12 at 08:42
  • If it's a complex object, it must be serialized (and you can't use GWT-RPC here). I would probably use [AutoBeans](http://code.google.com/p/google-web-toolkit/wiki/AutoBean#AutoBeanCodex) - they can be encoded and decoded automatically on the client and server. But basically any [technique](http://stackoverflow.com/questions/683123/json-java-serialization-that-works-with-gwt) can be used. – Chris Lercher Sep 22 '12 at 09:23