Thomas L Roche <[EMAIL PROTECTED]> Wed, 5 Feb 2003 18:37:04 -0500
>> [WSSD's Web Diagram Editor (WDE)] allows you to graphically design
>> a Struts application by drawing modules, actions, formbeans (and
>> regular javabeans), JSPs (and other web pages), etc and their
>> connections (kinda like your item 1). The items can be named at
>> "design-time," and you can then "realize" your design by launching
>> wizards from it.

ROSSEL Olivier Wednesday, February 05, 2003 12:58 PM
>> Does WSSD handle coordination between Action names in
>> struts-config.xml and in JSPs <html:form> ?

Yes. To illustrate:

<Why are there no @$#%^&*! marketing people to answer these questions?
 Where's our Flash demo, dammit?/>

here's a longer scenario. But first, 3 notes:

* The WSSD referenced is version 5.0 (not 4.x) with efix 1 (for an
  embarassingly self-inflicted bug. Not inflicted by _my_self,
  fortunately :-)

* This scenario uses Struts 1.0 for simplicity, but our tools also
  have 1.1 support.

* As previously mentioned,

Sri Sankaran Wed, 5 Feb 2003 13:04:18 -0500
> WSSD also has this "next generation wizard" that they call
> Cheatsheet. It literally walks you

  figuratively !-)

> through the process of building a Struts-based application.

  If you use the cheatsheet, it will automate (e.g. intelligently
  preset defaults for) even more of this. Use the cheatsheet by
  choosing, from the main menu,

  Help>Cheat Sheets>Create a Struts-based Web application

So here's another scenario to answer your question, from start
(blank workspace) to finish (test on server):

* Create a Struts project: launch the Web Project wizard (e.g. Ctrl-n,
  Web, Web Project), check "Add Struts support," give it a name (e.g.
  HelloWorld), hit Finish. (WPW allows you to choose Struts version,
  resource bundles, etc, copies your jars, sets classpaths, etc.
  For this, we take the defaults.)

  This will cause your workbench to go into Web perspective. If you're
  not there already, go to the J2EE Navigator view. (This is another
  thing that cheatsheet automates.)

* Create a web diagram (e.g. Ctrl-n, Web, Struts, Web Diagram): launch
  the Web Diagram wizard, give it a name, hit Finish. This creates a
  web diagram file (which is XML and works with the open Graphical
  Editor Framework, http://www.eclipse.org/gef) and puts you in its
  editor, WDE (which we do pronounce "woody," thank you, Sri :-)

In the WDE, add the following "blobs" (which represent not-yet-created
Struts artifacts). Note that adding is done by right-clicking on an
empty space, choosing New, and choosing kind of thing.

* Add a web page named /index.jsp

* Add a web page named /response.jsp

* Add an action mapping named /hello

* Add a form-bean named messageForm

Connect them: right-click on the source thingy>Connection and
draw to its target.

* Connect /index.jsp to /hello.

* Connect /hello to /response.jsp (and name the forward "success").

* Connect /response.jsp to /index.jsp.

* Connect /hello to messageForm.

* Connect messageForm to /response.jsp.

* Save the diagram (e.g. with C-s). This is good to do periodically :-)

Note that the icons are greyish and outlined: this indicates that they
are "unrealized," i.e. that you haven't created corresponding
artifacts. So let's create them now:

* Double-click /index.jsp: this launches the JSP Wizard to create it.
  Make sure the "Struts JSP" code generation model is selected, hit
  Finish. (If you're in the cheatsheet, it will take care of that, et
  al, for you.)

  This puts you in the file's editor (called Page Designer (PD)).
  Switch to the Source pane: you should see something like (minus
  citing)

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <html:html>
> <HEAD>
> <%@ page 
> language="java"
> contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"
> %>
> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <META name="GENERATOR" content="IBM WebSphere Studio">
> <META http-equiv="Content-Style-Type" content="text/css">
> <LINK href="theme/Master.css" rel="stylesheet"
>       type="text/css">
> <TITLE></TITLE>
> </HEAD>

> <BODY>
> <html:form action="/hello">
> </html:form>
> </BODY>
> </html:html>

  Remember that you connected /index.jsp to /hello? WDE remembered,
  too: so there's the answer to your question.

But, since I'm "on a roll":

* Remaining in the Source pane, insert some code into the form. E.g.
  make it

+ <html:form action="/hello">
+ <H1 align="center"><FONT color="green">Hello World Example</FONT></H1>
+ <P align="center">
+ Enter your Name: <html:text property="name"/><br>
+ <html:submit>Get the Message</html:submit>
+ </p>
+ </html:form>

* Switch to the Design pane to see it rendered nicely. Save and close
  the file.

* Double-click /response.jsp to launch the JSPW, remember to select
  the "Struts JSP" codegen model, hit "Finish". In PD you should see

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
> <html:html>
> <HEAD>
> <%@ page 
> language="java"
> contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"
> %>
> <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <META name="GENERATOR" content="IBM WebSphere Studio">
> <META http-equiv="Content-Style-Type" content="text/css">
> <LINK href="theme/Master.css" rel="stylesheet"
>       type="text/css">
> <TITLE></TITLE>
> </HEAD>
> <BODY>
> <P>Place response.jsp's content here.</P>
> </BODY>
> </html:html>

* Replace "Place response.jsp's content here." with your code, e.g.

+ <H1 align="center">
+ <FONT color="green">Hello World Sample Application Response</FONT>
+ </H1>
+ <center><h2>
+ Message:
+ <bean:write name="messageForm" property="message" scope="request"/>
+ </h2><p>
+ <A href="index.jsp">Click here to return to the Home Page</A>
+ </center>

* Check the rendering in the Design pane, save and close the file.

* Double-click messageForm to launch the ActionForm wizard. Note that
  by default it wants to create a class called
  helloworld.forms.MessageForm, among other things. Change defaults as
  desired.

* Hit Next to see the "Choose new accessors" page. This allows you
  to checkbox-tree-browse the form controls of all the web pages in
  all the projects in your workspace: it will then automatically
  create fields and accessors for them in your form-bean. 

  For now, just check the HelloWorld box (representing your project):
  this will select all the form controls in your project (which
  happens now to be only one, in only one page :-)

* Hit Next to see the "Create new accessors" page. This gives you a
  table view (name and type) of the fields for which you want to
  create accessors, and allows you to add/remove fields. Note that
  there is already a field named name, with type=String. Add another
  field named "message", and keep the default type String.

* Hit Next to see the mapping page (or skip it, because it does just
  what you'd expect).

* Hit Finish. This will create a new class with the two fields, their
  accessors, and reset and validate method skeletons, and show it to
  you in the Java editor. Twiddle, save, close.

* Double-click on /hello to launch the action mapping wizard. You
  should see that its

- path=/hello
- forward: name=success, path=/response.jsp
- formbean: name=messageForm, scope=request
- codegen model=Generic Action Mapping

  (These code generation models are extendable, and a wizard can have
  more than one ... but that a whole 'nother topic.) Change as desired.

* If you wanna see the class page, hit Next, and note that

- package=actions
- name=HelloAction

  etc. Since we're in a 1.0 project, it offers to create perform(...)
  stubs.

* Hit Finish to create the class and display it in the Java editor.
  Note the perform(...):

>   public ActionForward perform(
>     ActionMapping mapping,
>     ActionForm form,
>     HttpServletRequest request,
>     HttpServletResponse response)
>     throws IOException, ServletException {

>     ActionErrors errors = new ActionErrors();
>     ActionForward forward = new ActionForward();
>     // return value
>     MessageForm messageForm = (MessageForm) form;

>     try {

>       // do something here

>     } catch (Exception e) {

>       // Report the error using the appropriate name and ID.
>       errors.add("name", new ActionError("id"));

>     }

>     // If a message is required, save the specified key(s)
>     // into the request for use by the <struts:errors> tag.

>     if (!errors.empty()) {
>       saveErrors(request, errors);
>     }
>     // Write logic determining how the user should be forwarded.
>     forward = mapping.findForward("success");

>     // Finish with
>     return (forward);

>   }
> }

* Do something, e.g.

+     try {
+       messageForm.setMessage("Hello, " + messageForm.getName());
+     } catch (Exception e) {

  (but hopefully better i14ed :-) Save and close.

* WDE should now show all icons colorfully, indicating that they
  correspond to created artifacts.

* Double-click on messageForm: WDE will take you to the form-bean pane
  of the struts-config file editor (SCFE). Note that you can browse
  and modify all relevant properties there. If you make a mistake, you
  will get Struts-specific, project-aware errors or warnings.

* Go back to WDE, and double-click on /hello: WDE goes to the actions
  pane. Close SCFE (save if you make any changes).

You now have a complete (though very simple) app. To test it ...

Here's where my knowledge runs out--I only remember how to do this
with the cheatsheet. (I code wizards, so I only look at what gets
generated :-) If you've been creating your app with the cheatsheet,
and have been doing it step by step, you should now be at the "Run the
Web Application" step: hit the "perform" icon.

Otherwise, start the cheatsheet

main menu>Help>Cheat Sheets>Create a Struts-based Web application

and hit the "skip" icon for each step EXCEPT for the "Run the Web
Application" step. For that, hit the "perform" icon.

* This launches the "Server Selection" dialog. Set the "Create a new
  server" radio, select "Test Environment" under "WebSphere version
  5.0", and hit "Finish". Answer "Yes" if it asks you to create a
  "Server" project.

* The Console view will scroll a lotta text, the server will start,
  and a web browser view will open to show you /index.jsp. Enter
  something in the text field (e.g. "Olivier") and click the button:
  you get your response:

> Hello World Sample Application Response
> Message: Hello, Olivier
> Click here to return to the Home Page 

  as previously coded in /response.jsp.

Any questions? Feel free to ask about WSSD on its newsgroup

news://news.software.ibm.com:119/ibm.software.websphere.studio.application-site-developer

or ask your friendly local IBM marketing person. (Or ask me, but now
I gotta go do linear algebra :-(

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to