Hi there,
I am newbie in this field and have been struggling for hours now on how to integrate a Composite widget in GWT into Vaadin. If I run that Composite in GWT it works fine. Now what I would like is to integrate it in Vaadin and start playing with it in order to reach a full integration in Vaadin to use it in my applications.
From what I have understood so far, I need to:
- create a client class in Vaadin with the name (by convention) VMyWidget, that extends the Widget gwt class and implements the Paintable interface. Well, I don’t extend Widget directly but a class that extends the Composite gwt class. Should be correct.
- create the server component that extends the AbstractComponent class, and annotate it with @ClientWidget(fullclassname.class) pointing to the class created in step 1.
- Include the client class in a subpackage called “client”.
- Recompile the widgetset.
Well this isn’t working for me…
after several tests I tried to add a gwt.xml module in the same package as the server component, but also didn’t do the trick.
I also tried to replicate the structure from the Overlays Vaadin add-on but the gwt compiler keeps complaining:
[WARN]
Widget class mycomponent.client.ui.VAnchurasPaneles was not found. The component mycomponent.AnchurasPaneles will not be included in the widgetset.
Let me post 3 files, the client widget, the server component and the build-widgetset.xml file. Please anyhelp is greatly appreciated.
Code for the Client widget
package mycomponent.client.ui;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Container;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import mycomponent.GWTAnchuraPaneles;
/**
*
* @author Carlos Conti
*/
public class VAnchurasPaneles extends GWTAnchuraPaneles implements Paintable{
ApplicationConnection client = null;
String uidlId;
public VAnchurasPaneles(Double anchuras) {
super(anchuras);
}
/**
* This method must be implemented to update the client-side
* component from UIDL data received from server.
*
* This method is called when the page is loaded for the
* first time, and every time UI changes in the component
* are received from the server.
*/
public void updateFromUIDL(UIDL uidl,
ApplicationConnection client) {
// This call should be made first. Ensure correct
// implementation, and let the containing layout
// manage the caption, etc.
if (client.updateComponent(this, uidl, true))
return;
// Save reference to server connection object to be
// able to send user interaction later
this.client = client;
// Save the UIDL identifier for the component
uidlId = uidl.getId();
// Get value received from server and actualize it
// in the GWT component
//setColor(uidl.getStringVariable("colorname"));
}
}
where GWTAnchurasPaneles is the class tested in GWT which extends the Composite gwt class and works fine in GWT. Note that I took the code from the Vaadin Book V.6
Code for the Server Component
package mycomponent;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.ClientWidget;
import java.util.Map;
import mycomponent.client.ui.VAnchurasPaneles;
/**
*
* @author Carlos Conti
*/
@ClientWidget(VAnchurasPaneles.class)
public class AnchurasPaneles extends AbstractComponent{
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
}
@Override
public void changeVariables(Object source, Map<String, Object> variables) {
super.changeVariables(source, variables);
}
}
and finally the build-widgetset.xml buildscript I execute to recompile the widgetset which works smoothly to integrate vaadin add-ons:
<?xml version="1.0" encoding="UTF-8"?>
<project name="Compile Vaadin Widgetset" default="compile-widgetset" basedir=".">
<description>Compiles a combined widgetset of all Vaadin widgetsets found on the classpath.</description>
<!--
Important notice!!
This Ant script depends on the NetBeans project specific build-impl.xml
file. If you want to use this script in some other environment, you need
to manually create init and compile targets and define required properties.
See also http://demo.vaadin.com/docs/example-source/build-widgetset.xml
for another example script.
-->
<import file="nbproject/build-impl.xml"/>
<target name="widgetset-init">
<!-- Name of the widget set -->
<property name="widgetset" value="widgetset.MyAppWidgetSet"/>
<!-- Path to the widgetset directory. Required only for -->
<!-- generated widget sets. Must be relative to -->
<!-- $src.dir, that is, under the first entry in -->
<!-- classpath. -->
<property name="widgetset-path" value="widgetset"/>
<!-- Target where to compile the widget set -->
<property name="client-side-destination" value="web/VAADIN/widgetsets" />
<!-- Define if the widget set be generated automatically -->
<!-- from all widget sets included in the class path. -->
<property name="generate.widgetset" value="1"/>
</target>
<!-- Generates a combined widget set from all widget -->
<!-- sets in the class path, including project sources. -->
<!-- Updates the configuration if it already exists. -->
<target name="generate-widgetset" depends="widgetset-init, compile" if="generate.widgetset">
<echo>Updating ${widgetset}...</echo>
<echo>Remember to define the widgetset in web.xml as follows.</echo>
<echo>
<init-param>
<param-name>widgetset</param-name>
<param-value>${widgetset}</param-value>
</init-param>
</echo>
<!-- Create the directory if it does not already exist. -->
<mkdir dir="${src.dir}/${widgetset-path}"/>
<java classname="com.vaadin.terminal.gwt.widgetsetutils.WidgetSetBuilder" failonerror="yes" fork="yes" maxmemory="1024m">
<arg value="${widgetset}"/>
<jvmarg value="-Xss1024k"/>
<jvmarg value="-Xss1024k"/>
<jvmarg value="-Xmx1024m"/>
<jvmarg value="-XX:MaxPermSize=1024m"/>
<jvmarg value="-Djava.awt.headless=true"/>
<classpath>
<pathelement path="${src.dir}" />
<pathelement path="${javac.classpath}" />
<pathelement path="${build.web.dir}/WEB-INF/classes" />
</classpath>
</java>
</target>
<!-- Compiles the widget set using the GWT compiler. -->
<target name="compile-widgetset" depends="init, widgetset-init, generate-widgetset">
<echo>Compiling ${widgetset} into ${client-side-destination} directory...</echo>
<java classname="com.google.gwt.dev.Compiler" failonerror="yes" fork="yes" maxmemory="1024m">
<arg value="-war" />
<arg value="${client-side-destination}" />
<arg value="${widgetset}" />
<jvmarg value="-Xss1024k"/>
<jvmarg value="-Xmx1024m"/>
<jvmarg value="-XX:MaxPermSize=1024m"/>
<jvmarg value="-Djava.awt.headless=true"/>
<classpath>
<pathelement path="${src.dir}" />
<pathelement path="${javac.classpath}" />
<pathelement path="${build.web.dir}/WEB-INF/classes" />
</classpath>
</java>
</target>
</project>
So far I don’t think the integration is done correctly (for instance since its a Composite, I think I should use AbstractComponentContainer instead of AbstractComponent as the extended class in the server component), but I can’t do any steps forward either. These are my first steps in this direction and I am not being able to do even the basic stuff.
Thank you very much for your help.
Regards,
Carlos.