From jbosstools-commits at lists.jboss.org Tue Mar 10 10:39:18 2009
Content-Type: multipart/mixed; boundary="===============6639721800265897305=="
MIME-Version: 1.0
From: jbosstools-commits at lists.jboss.org
To: jbosstools-commits at lists.jboss.org
Subject: [jbosstools-commits] JBoss Tools SVN: r14147 -
branches/jbosstools-3.0.x/struts/docs/struts_tools_tutorial/en.
Date: Tue, 10 Mar 2009 10:39:18 -0400
Message-ID:
--===============6639721800265897305==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: ochikvina
Date: 2009-03-10 10:39:17 -0400 (Tue, 10 Mar 2009)
New Revision: 14147
Added:
branches/jbosstools-3.0.x/struts/docs/struts_tools_tutorial/en/master_ou=
tput.xml
Log:
https://jira.jboss.org/jira/browse/JBDS-655 - adding master_output.xml;
Added: branches/jbosstools-3.0.x/struts/docs/struts_tools_tutorial/en/maste=
r_output.xml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/jbosstools-3.0.x/struts/docs/struts_tools_tutorial/en/master_o=
utput.xml (rev 0)
+++ branches/jbosstools-3.0.x/struts/docs/struts_tools_tutorial/en/master_o=
utput.xml 2009-03-10 14:39:17 UTC (rev 14147)
@@ -0,0 +1,1340 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ =
+
+]>
+ =
+
+ Struts Tools Tutorial
+ =
+ AnatolyFedosik=
author>
+ OlgaChikvina
+ SvetlanaMukhina<=
email>smukhina(a)exadel.com
+ =
+ April 2008
+
+ 2007
+ 2009
+ JBoss, a div=
ision of Red Hat
+
+
+ Version: 3.0.0.GA
+
+
+
+
+
+ PDF version
+
+
+
+
+ =
+ =
+ =
+ =
+ =
+
+
+
+
+ JBoss Tools
+ Eclipse
+ Java
+ JBoss
+
+
+ Introduction
+ The following chapters describe how to deal with classic/old style=
of Struts development. We
+ recommend users to use JBoss Seam to
+ simplify development, but until then you can read about classical Stru=
ts usage here.
+
+ We are going to show you how to create a simple
+ Struts application
+ using the JBoss Tools. The completed application will ask =
a user to enter
+ a name and click a button. The resulting new page will display the fam=
iliar message,
+ "Hello <name>!"
+ This document will show you how to create such an application from=
the beginning, along the
+ way demonstrating some of the powerful features of JBoss Tools. With t=
he help of our tutorial you will design the
+ application, generate stub code for the application, fill in the stub =
coding, compile the
+ application, and finally run it all from inside the Eclipse.
+ =
+
+ Other relevant resources on the topic
+ =
+ All JBoss Developer Studio/JBoss Tools documentation you can fin=
d here.
+ The latest documentation builds are available here.
+ =
+
+ =
+
+
+ =
+
+
+
+
+ JBoss Tools
+ Struts
+ Struts Application
+
+
+ =
+ Creating a Simple Struts Application
+ =
+ Firstly, we assume that you have already launched Eclipse with J=
Boss Tools installed and
+ also that the Web Development perspect=
ive is the current perspective. (If not, make it
+ active by selecting
+ Window > Open Perspective > =
Other > Web
+ Development
+ from the menu bar.)
+ =
+
+ Starting Up
+ We are first going to create a new project for the applicati=
on.
+
+
+ Go to the menu bar and select
+ File > New > Project=
...
+ .
+
+
+ Select
+ JBoss Tools Web > Strut=
s > Struts Project
+ in the New Project dialog box
+
+
+ Click
+ Next
+
+
+
+ Enter "StrutsHello" as the project name
+
+
+ Leave everything else as is, and click
+ Next
+
+
+
+ Click
+ Next
+ again
+
+
+ Make sure that
+ struts-bean.tld
+ ,
+ struts-html.tld
+ , and
+ struts-logic.tld
+ are checked in the list of included tag librar=
ies and then click
+ Finish
+
+
+
+ A "StrutsHello" node should appear in the upper-left Package
+ Explorer view.
+
+
+ Click the plus sign next to
+ StrutsHello
+ to reveal the child nodes
+
+
+ Click the plus sign next to
+ WebContent
+ under StrutsHello
+
+
+ Click the plus sign next to
+ WEB-INF
+ under WebContent
+
+
+ Then, double-click on the
+ struts-config.xml
+ node to display a diagram of the Struts applic=
ation configuration
+ file in the editing area
+
+
+ At this point, its empty except for the background grid line=
s.
+
+ =
+
+
+ Creating the Application Components
+ Now, we will design the application by creating the individu=
al components as
+ placeholders first. (We dont have to complete all of the detai=
ls inside the components
+ until afterwards.)
+
+ Creating JSP Page Placeholders
+ Next, let's create and place two JSP pages. We will not =
write any code
+ for the files, but only create them as placeholders so tha=
t we can create links to
+ them in the diagram. We will write the code a little bit l=
ater.
+
+ Creating the Page Placeholders
+
+
+ Bring the Web Projects view to the front of =
the Package Explorer view
+ by selecting the
+ Web Projects=
property>
+ tab next to that tab.
+
+
+ Right-click the
+ StrutsHello &g=
t; WEB-ROOT (WebContent)
+ folder in the Web Projects view an=
d select
+ New > Folde=
r...
+
+
+
+ Enter
+ pages
+ for a folder name and click
+ Finish
+
+
+
+
+ We will keep our presentation files in this =
folder
+
+
+
+ Right-click the pages folder and select
+ New > Fila =
> JSP...
+
+
+
+
+ For Name type in
+ inputname
+ (the JSP extension will be automat=
ically added to the file),
+ for Template select
+ StrutsForm
+ and then click on the
+ Finish
+ button
+
+
+ Right-click the pages folder again and selec=
t
+ New > File =
> JSP...
+
+
+
+ For Name type in
+ greeting
+ , for Template leave as Blank, and =
then click on the
+ Finish
+ button
+
+
+ Just leave these files as is for now.
+
+
+ Placing the Page Placeholders
+ Lets now place the two pages just created on the dia=
gram.
+
+
+ Click on the
+ struts-config.=
xml
+ tab in the Editing area to bring t=
he diagram to the
+ front
+
+
+ Click on the
+ inputname.jsp<=
/property>
+ page in the Web Projects view, dra=
g it onto the diagram, and
+ drop it
+
+ Click on the
+ greeting.jsp
+ page in the Web Projects view, drag it=
onto the diagram, and
+ drop it to the right of the
+ /pages/inputname.j=
sp
+ icon with some extra space
+
+ You should now have two JSP pages in the diagram.
+
+
+
+ Creating an Action Mappings
+ Using a context menu on the diagram, we are next going t=
o create an Action
+ mapping.
+
+
+ Right-click between the two icons and select
+ Add > Action
+
+
+
+ Enter the following values:
+
+
+
+ ("GetNameForm" is the name for a form bean that we will =
create
+ later.)
+
+
+ Click
+ Finish
+
+
+
+
+ The
+ /greeting
+ action should appear in four places, in the di=
agram, under the
+ action-mappings node, under the struts-config.xml node in =
Tree view, in Web Projects
+ view and in the Outline view. Also, note the asterisk to t=
he right of the name,
+ struts-config.xml, in the Outline view showing that the fi=
le has been changed, but
+ not saved to disk.
+
+
+ Creating a Link
+ Let's now create a link from the inputname.jsp page to t=
he action.
+
+
+ On the left-hand side of the diagram in the colu=
mn of icons, click on this
+ icon:
+
+
+
+ Create New Connection Icon
+
+
+
+
+
+
+
+
+ In the connect-the-components mode you are in no=
w, click on the
+ /pages/inputname.j=
sp
+ icon in the diagram and then click on =
the
+ /greeting
+ action
+
+
+ A link will be created from the page to the action.
+
+
+ Creating a Forward
+ Next, we are going to create a forward for the action.=
para>
+
+
+ On the left-hand side of the diagram in the colu=
mn of icons, click on this
+ icon, again:
+
+
+
+ Create New Connection Icon
+
+
+
+
+
+
+
+
+ Click on the
+ /greeting
+ action icon in the diagram and then cl=
ick on the
+ pages/greeting.jsp=
+ icon
+
+
+ That's it. A link will be drawn from the actions=
new greeting
+ forward to the greeting.jsp JSP page. Note that th=
e forwards name will be
+ set based on the name of the target JSP file name.=
If you don't
+ like it, you can easily change it
+
+
+ Select the
+ Tree
+ tab at the bottom of the editor window=
(between Diagram and
+ Source)
+
+
+ Expand the
+ struts-config.xml/=
action-mappings//greeting
+ node and then select the greeting forw=
ard
+
+
+ In the Properties Editor to the right, change th=
e text to
+ "sayHello" in the Name field
+
+
+ Select the
+ Diagram
+ tab at the bottom of the editor window=
and see how the diagram
+ is also updated to reflect the change
+
+
+
+
+ Creating a Global Forward
+ One last component that we need to create in the diagram=
is a global forward.
+
+
+ Somewhere in the top-left corner of diagram, rig=
ht-click and select
+ Add > Global F=
orward...
+
+
+
+ Enter
+ getName
+ in the Name field
+
+
+ Select the
+ Change...
+ button for Path
+
+
+ In the Edit Path window, switch to the
+ Pages
+ tab
+
+
+ Expand the
+ StrutsHello > W=
EB-ROOT (WebContent) > pages
+ node and then select the inputname.jsp=
page
+
+
+ Click
+ Ok
+ .
+
+
+ Leave the rest of the fields blank and click
+ OK
+
+
+
+ A forward object now appears on the diagram and also in =
the global-forwards folder
+ in the Outline view.
+
+
+ Tidy up the diagram, by clicking and dragging ar=
ound each icon, so that
+ the diagram looks something like this:
+
+
+
+ Diagram View
+
+
+
+
+
+
+
+
+ Creating a Form Bean
+ One last thing that we need to do is to create a form be=
an.
+
+
+ Switch to the Tree viewer in the editor for the =
struts-config.xml file, by
+ selecting the
+ Tree
+ tab at the bottom of the editor window=
+
+
+ Right-click
+ struts-config.xml =
> form-beans
+ and select Create Form Bean
+
+
+ Enter
+ GetNameForm
+ in the name field and
+ sample.GetNameForm=
+ for type
+
+
+ Click
+ Finish
+
+
+
+ To save your changes to struts-config.xml, selec=
t
+ File > Save
+ from the menu bar
+
+
+ Note the disappearance of the asterisk next to the name,=
struts-config.xml.
+
+
+
+ =
+
+
+
+
+ JBoss Tools
+ Struts
+ Struts Application
+
+
+ =
+ Generating Stub Coding
+ We are done with designing the application through the diagr=
am. Now we need to write
+ code for the action component. We also need to write an action=
class for the
+ /greeting
+ mapping along with a FormBean. To aid in the codin=
g phase, JBoss Developer
+ Studio can generate Java class stubs for all of the components=
shown in the diagram.
+
+
+ Switch back to the diagram, by selecting the
+ Diagram
+ tab at the bottom of the editor window
+
+
+ Right-click a blank space in the diagram and select =
+ Generate Java Code
+
+
+
+ Leave everything as is in the dialog box and click <=
emphasis>
+ Generate
+
+
+
+ You should see a screen that says:
+ Generated classes: 2
+ Actions: 1
+ Form beans: 1
+
+
+ Click
+ Finish
+
+
+
+ The Java files will be generated in a
+ JavaSource > sample
+ folder that you can see in the Package Explorer view u=
nder the
+ "StrutsHello" node. One Action stub and one FormBean stub will=
have
+ been generated.
+
+ =
+
+
+
+
+ JBoss Tools
+ Struts
+ Struts Application
+
+
+
+ Coding the Various Files
+ We will now code both the Java stub classes just generated, =
the JSP files left in as
+ placeholders from previous steps, and a new start JSP page we =
will have to create.
+
+ Java Stub Classes
+
+
+ To finish the two Java classes, switch to the
+ Package Explorer=
property>
+ view and expand the
+ JavaSource > sa=
mple
+ folder
+
+
+
+ GetNameForm.java
+
+
+ Double-click
+ GetNameForm.ja=
va
+ for editing
+
+
+
+ You are looking at a Java stub class that wa=
s generated by JBoss
+ Developer Studio. Now we are going to edit the=
file
+
+
+
+ Add the following attributes at the beginnin=
g of the class:
+
+
+
+
+
+
+ Inside the reset method, delete the TO DO an=
d throw lines and
+ add:
+
+
+
+
+
+
+ Inside the validate method, delete the TO DO=
and throw lines and
+ add:
+
+
+
+
+
+
+ Right-click and select
+ Source > Ge=
nerate Getters and Setters...
+ from the context menu
+
+
+ In the dialog box, check the check boxes for=
name and greetName,
+ select First method for Insertion point, and c=
lick on the
+ OK
+ button
+
+
+ The final GetNameForm.java file should look like thi=
s:
+
+
+
+
+ Save the file
+
+
+
+
+ GreetingAction.java
+
+
+ Open GreetingAction.java for editing
+
+
+ Inside the execute method, delete the TO DO =
lines and add the
+ following:
+
+
+
+
+
+ The final version of GreetingAction.java should look=
like this:
+
+
+
+
+ Save the file
+
+
+ Close the editors for the two Java files
+
+
+ The last thing left to do is to code the JSP files w=
hose editors should still
+ be open from having been created as placeholders.
+
+
+
+ JSP Pages
+
+ inputname.jsp
+ In this page, the user will enter any name and click=
the
+ submit
+ button. Then, the greeting action will be =
called through the form.
+
+
+ Click on the
+ inputname.jsp<=
/property>
+ tab in the Editing area to bring i=
ts editor forward
+
+
+ In the Web Projects view, expand
+ StrutsHello &g=
t; Configuration > default
+ > struts-config.xml > action-map=
pings
+ and select
+ /greeting
+
+
+
+ Drag it and drop it between the quotes for t=
he
+ "action"
+ attribute to the
+ <html:form&=
gt;
+ element in the Source pane of the =
editor
+
+
+ Then type this text on a new line just below=
this line:
+
+
+
+
+ Select the
+ Visual
+ pane of the editor
+
+
+ Then, in the JBoss Tools Palette, expand the=
+ Struts Form
+ library, select
+ text
+ , and drag it onto the box
+
+ Note:
+ By default there are only four group=
s on the JBoss Tools
+ Palette. If you wish to make some grou=
p visible click the
+ Show/H=
ide
+ button on the top of palet=
te and in the prompted
+ dialog check the group (or groups) you=
want to be shown.
+
+
+
+
+
+ JBoss Tools Palette
+
+
+
+
+
+
+
+
+ In the Insert Tag dialog box, type in name f=
or property and select
+ Finish
+
+
+
+ In the StrutsForm library in the JBoss Tools=
Palette, select
+ submit
+ , and drag it to right after the te=
xt box in the Visual pane
+ of the editor
+
+
+ Right-click the
+ submit
+ button and select
+ <html:submi=
t>
+ Attributes from the context menu=
para>
+
+
+ In the Attributes dialog box, select the
+ value
+ field and type in "Say Hello!" for=
its
+ value
+
+
+ After tidying the page source, the Editor window for=
the file should look
+ something like this:
+
+ Editor Window
+
+
+
+
+
+
+
+
+ greeting.jsp
+ Next, we will fill in the result page.
+
+
+ Click on the
+ greeting.jsp=
property>
+ tab in the Editing area to bring i=
ts editor forward
+
+
+ Type in the following code:
+
+
+
+
+ Greeting
+
+
+