I've been using smartGWT for a few years but have started looking at Vaadin. I've got the example running but am stumped when it comes to writing the RPC call.
I have a connector:
public class MyComponent2Connector extends AbstractComponentConnector {
And add this to my UI:
#SuppressWarnings("serial")
#Title("StyleSuite Title")
public class MyVaadinUI extends UI
{
private final MyComponent2Connector c = new MyComponent2Connector();
But when I visit the site it says:
java.lang.NoClassDefFoundError:
com/example/suite_local/client/mycomponent2/MyComponent2Connector
The gwt.xml is very plain and just has:
<inherits name="com.vaadin.DefaultWidgetSet" />
I'm clearly doing something wrong - anyone have any pointer for setting this up or have an exampe project?
Vaadin is a server-side framework, which uses GWT in the client-side to render widgets. Normally you only code serve-side stuff and you don't need to worry about RPC or other communcation between server and client because Vaadin takes care of it under the hood. But if you implement your own widget, then you need RPC (or shared state).
Your problem is that you are trying to use a client-side GWT class (MyComponent2Connector) from a server-side class (MyVaadinUI), that doesn't work (as you see). Vaadin 7 mini tutorials is good reading and also Book of Vaadin to understand how Vaadin works.
Related
I would like to integrate ganttchart GWT widget with vaadin7 application available at https://code.google.com/p/gwtgantt/
I went through some links which explores about integrating GWT widgets with vaadin7 but I don't think I understood.
Also, Do I need to write the connector and other stuff in vaadin to integrate GWT widgets? If yes then I am not quite sure what I will be writing in that.
Does anyone tried the same GWT widget with vaadin7 before?
Any pointers or Sample code will be really appreciated.
Regards,
Azhar
When you are able to use Vaadin 7, this wiki article should help you to get started:
https://vaadin.com/wiki/-/wiki/Main/Integrating%20an%20existing%20GWT%20widget
I believe it handles exactly what you are asking for.
Basically, you need to write the server side code for GWT widgets, and extends the GWT widgets with the communication capability. Here a good project for you to get start with https://github.com/360-Innovations/VaadinSmartGWT
A little example (for Vaadin 6):
1 use eclipse with Vaadin plugin installed to create a Vaadin project then create Vaadin widget unpon that project, Vaadin plugin will generate all the nuts and bolts.
2 write the code
a client class wrapper for GanttChart It implements Paintable interface to communicate with server side
public class VGanttChart extends GanttChart implements Paintable {
public void paint(PaintTarget target) throws PaintException {
}
public void requestRepaint() {
}
... ...
}
for use of each methods, please look at the source comments at Paintable.class
a server side corresponding class:
#ClientWidget(value = VGanttChart.class, loadStyle = LoadStyle.EAGER)
public class GanttChart extends AbstractComponent {
public void paintContent(PaintTarget target) throws PaintException {
}
public void changeVariables(Object source, Map<String, Object> variables) {
}
... ...
}
3 exporting as Vaadin Add-on Package, this is also provided by Vaadin plugin.
4 add the exported jar to your project /WEB-INF/lib, edit your XXXWidgetset.gwt.xml file by adding your add-on's widgetset like this:
<inherits name="package path to your add-on's widgetset def file"/>
if your widgetset def file is myWidgetset.gwt.xml, then the value for attribute name should be "package path to widgetset"/myWidgetset
5 Compile your Widgetset, this is also provided by Vaadin eclipse plugin, after compilation, new set of javascript, css, image resource was generated, now you can use your add-ons via the server side class.
I’m trying to create a backend for a homepage with GWT. I created a Google Web Application in Eclipse without sample code and now I would like to add the service, but the developer Google guide doesn’t help me. I’m not sure, where to add the interface and how it exactly works.
If I understand the google documentation correctly, I have to add a module and an entry point class, is that correct? It would be great if you could give me some tips and help how to create a rpc service.
If you create a new GWT project in the Eclipse "New Project" wizard, with "Generate project sample code" checked, it will include a fully functioning RPC service with a sample method, which you can then adapt or copy according to your needs.
Out of memory, don't have eclipse in front of me.
First do create a test project with generated testcode, you can delete it afterward.
Yes you will have to add a module.
Create in client the two interfaces for the async calls, inherit it on server side.
Hope I understood your question right.
I'm not sure what would help you the most. Google developer guide was enough for me (at least when I started using it on version 1.6) to create RPC services for my GWT application.
General APP
Module: is the .gwt.xml file. Yes, you'll need it. The GWT compiler will find it automagically and try to compile all the GWT code (the <source> element will tell which subpackage contains Java code that will be converted to JS). It will tell also which class implements the EntryPoint interface. The onModuleLoad will be the code executed when javascript runs in the client page.
RPC
Well, you should first try UI things and only then, when you're confident enough, try the server thing. Anyway the scheme is:
interface MyService extends RemoteService {
List<String> doSomething(String sample, int other);
}
#RemoteServiceRelativePath("../path/to/servlet") // see later
intercace MyServiceAsync {
void doSomething(String sample, int other, AsyncCallback<List<String>> callback);
}
These are the interfaces. Later is the async one. That's what you'll use from client side. Always calling and passing an implementation of AsyncCallback which will receive (sometime later, you don't know when) the result.
First interface is the syncrhonous one. That is what you need to implement on server. You must inherit from RemoteServiceServlet class (it is an implementation of servlet that already does all the values handling), and implement your interface. GWT code does the rest (almost).
public class ServiceImpl extends RemoteServiceServlet implements MyService
{
// implement the method normally
}
From client you'll need to create the service proxy:
private static MyServiceAsync MY_SERVICE = GWT.create(MyService.class);
Yes. I know it's weird how GWT knows MyserviceAsync and MyService work together. Don't worry about that. It works :)
Just use the service like this:
MY_SERVICE.doSomething("value", 111, new AsyncCallback<List<String>>() {
// note that this code executes some time in the future when response from server is back
public void onSuccess(List<String> result) {
Window.alert("Server answered with " + result.size() + " elements!");
}
public void onFailure(Throwable t) {
Window.alert("Server failed: " + t.getMessage());
}
}
Path to server
You'll have to configure your app to make that servlet implementation listen to URL indicated in #RemoteServiceRelativePath. That's the way client knows where to make the request, and the server knows which servlet attends that request. I'd suggest using:
../my-service.gwt as relative path (GWT module gets published in <ROOT>/module_name
and
configuring your web app to use the servlet for /my-service.gwt
But it's entirely upon your preferences :)
Anyway I think Google tutorials are the best. So please copy&paste. Try&modify until you get to understand the whole thing.
I am a newbie at GWT and I have the following query.
I have a scenario where I am trying to develop a web interface(using GWT) for an existing application.
In the client side class file I would like to invoke a user specific class file, i understand that this is due to the fact that i am trying to invoke classes other than the ones http://code.google.com/webtoolkit/doc/latest/RefJreEmulation.html
I would like to know how this code can be called from the client side of the ui.
Thanks and Regards,
Bhavya
If you have a source code for the class you want to use and it is using only the supported Java classes, you can simply add your specific classes to client packages. If this is a reusable code, you can create a new GWT module and inherit it in your application. You can also simply move those classes to your client packages OR add a new client folder in you .gwt.xml file (add one more <source> tag)
If your class is not compilable by GWT, then I think you need to use it through RPC service.
If the code is translatable into JavaScript, you could for example put your individual class files into a jar and add it to the Build Path - as you would do in a 'regular' Java Project.
I want to use GWT with seam Framework, so i add the jar gwt-user-2.2.0.jar to my project. but when i invoke any method from the view (a xhtml page ) this exception is occured:
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.client.GWT.create(GWT.java:92)
at com.google.gwt.user.client.ui.UIObject.(UIObject.java:188)
... 84 more
I use seam v2.2,I can post the code :
#Name("scheduleHandler1")
public class SheduleHandler1 implements Serializable,EntryPoint
{
public void onModuleLoad() {
MyPopup p = new MyPopup();
RootPanel.get().add(p);
}
From my xhtml view i call this method:
<h:commandLink value="showPopup" action="#{scheduleHandler1.onModuleLoad}" />
Thanks for Help.
GWT is client side technology - the java code that you write compiles down to js+html and is executed inside the browser.
OTOH, SEAM is server side technology - code that you write executes on server when a request is made and the HTML is produced which is returned back to browser for display.
In this sense GWT and Seam do not go well together. Most certainly you can not mix the code in the same compile unit.
You could use Seam for server side REST and GWT on the client side to consume REST, but this would only make sense if you already had an existing Seam REST code.
If you have written some GWT code and want to include it in you html pages (static or produced by Seam) then use them as GWT host pages - you simply include script tag to include GWT js code in the page: http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html
GWT and Seam can actually work together, as you can see in this page in the Seam Reference Documentation.
However, what it looks like you are trying to do, and where the problem looks to me, is that you are trying to mix JSF and GWT. You are trying to call a Seam action from JSF where that action calls some GWT code. Hence, your server side Seam code is calling the client side GWT code and you are getting the exception that says GWT.create() is only usable in client code! It cannot be called, for example, from server code. I'm not sure why you're trying to do this.
JSF is a client side technology, written in XHTML. GWT is also a client side technology written in, well, Java. I'm not sure how these play together.
On the other hand, there is no reason, as per the link above, why your GWT widgets cannot call your Seam components. You just need to follow the instructions.
I'm wondering is there a similar framework like Vaadin built on top of GWT which wraps the original GWT components but with server-side only event handling? (I know that Vaadin is built on top of GWT. I'm looking for an alternative solution.)
Vaadin is nice because of it's precompiled nature. I found compile times with GWT horrific the last time i've worked with it. Also it's a bit easier to maintain security if event handling code runs on the server. It would be nice if the standard GWT could be used in a similar way.
I don't think there is another like vaadin. and vaadin is already server-side..
see this http://vaadin.com/learn for more info
Have you seen this? - http://code.google.com/p/gwteventservice/
For server-side alternative, you might take at a look at ZK too.
Notice that its client side is based on jQuery, not GWT. However, you won't notice it at all since they both are server-side solutions and using pure Java.
Event handlers that you normally deal with are in server-side Java code. Consider this:
final Button testButton = new Button("Test Button");
testButton.addListener(new Button.ClickListener()
{
#Override
public void buttonClick(ClickEvent event)
{
mainWindow.showNotification("I am server-side code!");
}
});
As you said, you need to compile GWT code only when adding a custom component to your code. Vaadin's built in components are already compiled and put in the jar file. Although sometimes your IDE might detect your project as a GWT project and try to compile the widgetsets every time you change the code, when you might want to ask it to ignore.
If you look for alternatives to Vaadin you might have a look at Echo2.