> Overview (Steps)

Struts lesson 4: Creating the Session-Bean with the 'Model'

For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

Last revision of this document:
2005-08-18



Preface:

First, this lesson is far away from the Struts-framework.
While writing the lesson about the Struts-framework incorporating a Session-Bean, I realized that this would mean a lot of typing before any result is seen.
And if there is a typing error - no result is shown at all.

So I excluded the writing of a Session-Bean into this lesson.

Another main-task of this lesson is to use XDoclet.
XDoclet is a technique to control the generation of code or parameterization-data by incorporating XDoclet commands in the developed program-files.

Credits:

A very good seed was the JBoss-IDE 1.3.0 Tutorial Guide by Hans Dockter and Laurent Etiemble.

Prerequisites:

Preparation:

Create a new project (named JS_Struts04) in Eclipse:

top.

Defining the Libraries in the Java Build Path:

Here all the standard-libraries with classes called either by individual code or by Struts-functions are defined.
These are defined now as otherwise errors are indicated when the Java-code for the servlet is written.

top.

Defining the static values:

When incorporating the project of this lesson into the next lesson, the time/date-format can be choosen by a combo-box.
To have this values (for the choice) available, they are defined in an Java-'Interface'.

A short explanation of the code.

Create and code the Session-Bean:

The Session-Bean contains the 'Business-Logic' ('Model' in Struts-terminology).
For simplicity, the first Session-Bean in my series of tutorials is a 'Stateless Session-Bean'.
Stateless means, that a Method of the session bean is called and returns a result without keeping any data for the next call.

A short explanation of the code.

top.

Defining the XDoclet parameters:

XDoclet is a technique, where code can be generated out of 'comments'. The XDoclet-engine is extremely powerfull and not only restricted to Java, EJB or Eclipse - but it would give you a headache trying to understand the functions completely.

For this lesson we can rely on the fact, that the was delivered with pre-configured command-files for the XDoclet-engine and allows functions necessary to develop EJBs (Enterprise Java Beans) and Web-Services.

The following instructions are to parameterize the XDoclet-generation by 'point and click' - and entering some text every now and then.

Do the configuration as follows:

top.

Making the packaging configuration for the files to be deployed and pack the files into a JAR (Java-ARchive):

For instructions how to define the files to be packed into the JAR-file, please see the instruction with screen shots at Making the packaging configuration and pack the HTML-files into a WAR (Web-ARchive) of JS_Struts02 – JSP in an EAR.

Name of the file or the folder to be packed into the JS_Struts03.war file

Prefix as to be entered on the window
'Folder Selection' or 'File Selection'

Reason

Folder 'gen/classes'


Class after compiling the written Java-code for the Beans and Interfaces.

File 'gen/META-INF/ejb-jar.xml'

META-INF

General deployment-information for the Java-Application-Server.

File 'gen/META-INF/jboss.xml'

META-INF

Particular deployment-information for the JBoss Java-Application-Server.

top.

Making the packaging configuration for the libraries used by fat-clients or web-services and pack the files into a JAR (Java-ARchive):

This step is not absolutely necessary to deploy the result of this lesson.
It is a prerequisite for client-programs (either stand-alone / fat-clients or servlets within a web-service).
It is also possible to skip it and do it before writing a fat-client or a web-service.

For instructions how to define the files to be packed into the JAR-file, please see the instruction with screen shots
at Making the packaging configuration and pack the HTML-files into a WAR (Web-ARchive) of JS_Struts02 – JSP in an EAR.

top.

Run / Test:

This is the final verification if the generated 'JS_Struts04EJB.jar' file (with an Java ARchive structure) is running error-free within a Java-Application-Server.

For the conceptional background of deployment to a Java-Application-Server and the assumptions of the directories with the Eclipse-workspace and and the Java-Application-Server-deployment, please see Run / Test in JS_Struts01 – HTML in a WAR .

Note: There is also a functionality in Eclipse to define the Java-Application-Server and deploy and undeploy with an Eclipse-function.
I was not pretty happy with that feature. My
JBoss-Application-Server is running on another machine. When this machine is not running during the start of Eclipse, the Eclipse-function gets confused, reports that a changed WAR-file is deployed - but the old file is not overwritten.
So I prefer to stay on the more secure side and copy the files using the 'Terminal'-window.

top.

Related Documents: