|
In this section we want to show in
detail how to creating a JavaClient project. The lack of support
of wolips for the development of a JavaClient project renders the
things a little more cumbersome. Actually many step can be become
simpler to you just copying from one of the examples (this are
true for the Components Main and JavaClient, build.xml, etc.). The
following suppose you have already installed the JPBinding.framework
in /Library/Frameworks/.
Create
the project
In
order to create from the scratch an eclipse+wolips project for a
Java Client which uses XML Binding one have to create in eclipse a
new WebObjects Application. Leaves blank the base package
and components package
Fixes sources consequently
(Application.java, DirectAction.java, Main.java, Session.java). In
the Main.java add the following method
public String javaClientLink() {
return WOJavaClientComponent.webStartActionURL(context(), "JavaClient");
}
Add also the following import
declaration
import com.webobjects.eodistribution.WOJavaClientComponent;
In Session.java add the following
method
/* return the fileName in WebServerResources as NSData */
public NSData clientSideRequestDataForFile(String fileName) throws IOException {
InputStream stream = WOApplication.application().resourceManager().inputStreamForResourceNamed(fileName, null, null);
return new NSData(stream, 512);
}
also add the following import
declarations
import com.webobjects.appserver.WOApplication; import
com.webobjects.foundation.NSData; import java.io.*;
Adjust the frameworks
Now you need to add some frameworks. In
the eclipse WO Package Explorer view, right click WebObjects
Frameworks Configure...
In System you need to add then
following frameworks:JavaEOAccess, JavaEOApplication, JavaEOControl,
JavaEODistribution, JavaEOInterface, JavaEOInterfaceSwing,
JavaFoundation, JavaJDBCAdapter, JavaWebObjects,
JavaXML
In Local you have to add PostgresqlPlugin,
or other if you use another db. Then, if you are in WO 5.5.3
you have also to add the JPBinding framework. You don't
have to add JPBinding if you are in WO 5.4
Due a WOLips problem that does not
include in then classpath the client frameworks, you need to do
this manually as external jar. In the eclipse WO Package Explorer
view, right click WebObjects Frameworks Build Path ->
Configure Build Path...
then click the Add External JARs... button.
Browse to the
/Library/Frameworks/JPBinding.framework/WebServerResources/Java folder
and select all the files that are in those folder
Click Open button and you would
have to see a window like this
Add the swing interface class
First
of all we create in the eclipse project the package in which
then we would go to insert the swing class, like admission.client.
Then we create a new class which must extend EOSwingInterface,
i.e. AdmissionJCSwingInterface.java
After to have created the class that
extends EOSwingInterface, you can just wrote the following code
public class AdmissionJCSwingInterface extends EOSwingInterface {
private JFrame _mainFrame;
public AdmissionJCSwingInterface() {
super();
}
protected void initGUI() {
_mainFrame = new JFrame();
}
}
then you can open the AdmissionJCSwingInterface.java
whith jigloo
Now you can play with the gui editor. jigloo
add the generated gui code in the initGUI() method. You have
not had to modify at all the code generated from jigloo. If you
prefer that all the generated code is in initGUI()
method you have choose the jigloo code block generation in the
jigloo preferences. The other options are: using getters
(code generated inside initGUI() + getters methods) and decide
based on context, see the jigloo preferences in the following
image
In order to use in profitable way
jigloo, I suggest you to add EOTable in the jigloo Custom
Component palette. Actually, between all the widget that they
are used in the xml binding, EOTable s the only one that is
not a swing component.
Keep in mind that JPBinding does not
have any particular support for jigloo. The only one assumption that
JPBinding makes is that the code of the GUI is initialized in initGUI()
method. Therefore you can very well try to use JPBinding with
JFormDesigner or with any other tool or to just code by hands.
Adjust
the components
Now I
have to modify component the Main.Copy and paste the
following in the Main.html
<HTML>
<HEAD>
<TITLE>Main</TITLE>
</HEAD>
<BODY>
<CENTER>
Please
<WEBOBJECT NAME=JavaClientLink>click here</WEBOBJECT>
to start AdmissionJC through WebStart.
</CENTER>
</BODY>
</HTML>
and the following in the Main.wod
JavaClientLink: WOHyperlink {
href = javaClientLink; //VALID
}
Now you must create with eclipse a new
one Component (New -> WOComponent) and name it JavaClient.
Here is the JavaClient.html content
<WEBOBJECT NAME=JavaClientComponent></WEBOBJECT>
and here is the one of JavaClient.wod
JavaClientComponent: WOJavaClientComponent {
applicationClassName = "admission.client.AdmissionJCSwingInterface";
applicationName = "AdmissionJC";
applicationDescription = "Description";
downloadClientClasses = "customBundlesClientClasses";
vendor = "Vendor";
}
The value of the applicationClassName
property is important. It indicates the swing interface class that
we want is the entry point of the application. We must use
the qualified name of that class
Adjust
the build.xml file
A JavaClient project must actually build the resources of two
applications, a server-side and a client-side
application. wolips it only builds the jar for the server-side
application (once completed the build, it will be found in the
folder Resources). In order to build the jar stuff for the
client-side application we must add a ant target to the build.xml
project file. In such a way we will be able to find the client-side
jar in the WebServerResources folder. Therefore add the
following code to the build.xml project file
<target name="javaclient">
<mkdir dir="${dest.dir}/${project.name}.woa/Contents/WebServerResources/Java"/>
<jar basedir="${classes.dir}" includes="**/client/**/*.class,**/common/**/*.class"
jarfile="${dest.dir}/${project.name}.woa/Contents/WebServerResources/Java/${project.name}.jar">
</jar>
</target>
then add the created new javaclient
target to the depends target list of the build and install
target, modifying the first lines of the build.xml file
<target name="build" depends="setProps,init.build,build.woapp,javaclient,ssdd,war" />
<target name="install" depends="setProps,init.install,build.woapp,javaclient,ssdd,war" />
We must also avoid that the binary of
the classes relating to the client-side application are in the
server-side jar. For this purpose we insert in the classes.exclude.patternset
file under the woproject folder. Replace the first line that
has the written one
build.properties
with
**/client/**
Adjust the build.properties file
You have to verify that the value of the
property principalClass in the build.properties file
is correctly set up
principalClass=Application
|