Tuesday, December 30, 2003

warneronstine.com | home

warneronstine.com | home

I get a lot of ideas and inspiration from talking to Warner.
Warner lives in Tucson and is the guy who originally turned me onto PicoContainer and Maven.

Sunday, December 28, 2003

DynaActionForms

An anomyous friend emails me:


one strong point i have against DAF - in XDoclet - try doing validation any easier than that!!!! (can't do it with DAF, that is for sure).


I have used XDoclet's Struts Validator framework support. (BTW That part was written by Erik Hatcher a former co-worker who is still a good friend of mine.) I think XDoclet's Struts Validator framework puts the final nail in the coffin of DAF IMHO.

Like I said before... I can work with them but I don't like them. (not on a tree; not with a bee; not on a bus; not with gus)

Saturday, December 27, 2003

Not a fan of DynaActionForms

DynaActionForms:

DynaActionForms are universally loved and hated. In teaching, consulting Struts and developing with Struts, I have found that DynaActionForms are either embraced or rejected. The idea behind DynaActionForms is that instead of creating an ActionForm per form, you instead configure an ActionForm per form.

Advantages:
Some folks feel creating an ActionForm class for each HTML form in your Struts application is time-consuming, causes maintenance problems, and is frustrating. With DynaActionForm classes you don’t have to create an ActionForm subclass for each form and a bean property for each field. Instead you configure an DynaActionForm its properties, type, and defaults in the Struts configuration file.

Deltas :
You still have to create the DynaActionForm in the struts configuration file. When you use the DynaActionForm, you have to cast all the properties to their known type. Using a DynaActionForm is a lot like using a HashMap. In your Action if you are accessing a DynaActionForm, if you screw up a property name (misspell it) the compiler will not pick it up, instead you will get a runtime exception. If you cast an Integer to a Float by mistake the compiler will not pick it up, you will get a runtime exception. DynaActionForms are not type safe. If you use an IDE, code completion does not work with DynaActionForms. If you override the reset method, you defeat the purpose of having a DynaActionForm. Another point is that DynaActionForms are not very dynamic, as you still have to change the configuration file, and then restart the web application to get Struts to recognize an additional field.

TIP: As you can probably tell, I think using DyanActionForms is less than ideal. I feel DynaActionForms are not really dynamic at all since you have to restart the web application when you change them. I find them no more dynamic than using Java classes. I prefer to create my ActionForms by subclassing ActionForm and using bean properties. I find that modern IDEs make short work of adding JavaBean properties. I see no real advantage to using DynaActionForms over ActionForms. If I want to make an ActionForm dynamic, I add a mapped backed property. I have worked on projects that forced DynaActionForms. I much prefer regular ActionForms.

I can use DynaActionForms. But, I could also code with one hand tied behind my back. In both cases, I don't see why.

AppFuse

This sounds like something I might use on my next Struts project:

What is AppFuse?
An application for starting your web applications. Checkout from CVS and execute "ant -Dapp.name=yourApp -Ddb.name=database" to instantly be up and running with a Tomcat/MySQL app. Uses Ant, XDoclet, Hibernate, JUnit, Cactus, StrutsTestCase, Canoo's WebTest, Struts Menu, Display Tag Library, JSTL and Struts (including Validator and Tiles). Features include CMA, Remember Me, Self Registration, Password Hint. The fuse to start your apps.

Struts IOC

struts.sf.net

Pretty cool Struts site. They have a plugin that integrates Struts with Spring.


The goals of the Struts Applications Project are:

to provide example Struts applications,
to host Struts extensions and utilities, and
to put the code out where the Community can use it, fix it, and maintain it
The Struts Applications Project currently consists of the following sub- projects:

AppFuse - A baseline Struts application to be used for future web applications
Polls - A survey-management Struts application
Struts Action Invocation Framework (SAIF) - Adds features like Action interceptors and Inversion of Control (IoC) to Struts.
Struts BSF - A Struts Action implementation that uses BSF-compatible scripting languages.
Struts Cocoon - Integrates Struts and Cocoon, using Cocoon for the presentation layer
Struts Resume - An application written using AppFuse as a foundation.
Struts Spring - Integrates Struts and the Spring Inversion of Control (IoC) framework.
StrutsDoc - A JavaDoc-type documentation tool for Struts and Struts-related configuration files
AppFuse
An application for starting your Struts-based applications. Checkout from CVS and execute "ant -Dapp.name=yourApp -Ddb.name=database" to instantly be up and running with a Tomcat/MySQL app. Uses Ant, XDoclet, Hibernate, JUnit, Cactus, StrutsTestCase, Canoo's WebTest, Struts Menu, Display Tag Library, JSTL and Struts (including Validator and Tiles). Features include CMA, Remember Me, Self Registration, Password Hint. The fuse to start your apps.

Polls
A simple survey application. Deploy the .war file on your servlet container to see it running. Read the instructions provided to see all the options available. Uses Hibernate, Struts, and JSTL.

Struts Action Invoocation Framework (SAIF)
A set of Struts extensions to improve how Struts handles Actions adding features like Action interceptors and Inversion of Control (IoC).

Struts BSF
This project allows Struts Actions to be written in the scripting language of one's choice rather than as Java classes. It uses the Beans Scripting Framework to allow scripts to be written in any language BSF supports like Perl, Python, Ruby, JavaScript, and BeanShell.

Struts Cocoon
This is a Struts 1.1 plugin that integrates Cocoon into the Struts framework. Struts forwards are passed to Cocoon to be rendered in Cocoon XML pipelines. Struts is a familiar and proven application framework and Cocoon is a very powerful and flexibile XML presentation technology. The project includes both the plugin and a slightly modified Struts example web application to show how easily Cocoon can be added to an existing Struts application.

Struts Resume
An application written using AppFuse as a foundation. Future plans include the ability to create an online resume and render it's contents with XSL/XML or Velocity.

Struts Spring
This project integrates the Spring Framework's Inversion of Control (IoC) into Struts 1.1+. It allows a Struts application to take advantage of IoC with little or no references to Spring. Now, instead of relying on singletons and static factories, Struts actions can have their dependencies automatically resolved.

StrutsDoc
A JavaDoc-type documentation tool for Struts and Struts-related configuration files. Extensive use of Xalan to transform Struts-related configuration files into text-based documentation.


funny email I got from a good (anoymous friend)

My friend writes...

"""
i saw you mentioned Tapestry on your blog - have you tried it? careful if you do, you might be embarrassed to be doing so much with Struts when you give it a try :) we are going full-on with Tapestry at BLANK and loving it!

JSF sucks. money schmoney - i'd rather work at McDonald's than use JSF.

p.s. your blog still looks lousy in Safari - you should try it out on a Mac in Safari sometime and see what i mean.
"""




BTW What is this thing you call Mac? I just bought a new laptop. I considered a Mac. But I bought a really nice 17inch HP laptop for half the price, and it is fast as a bat out of jail. And, the great thing is that all the software I use already works on my HP. I wanted to go with the Mac, but could not. There is this software package I must use that does not run on a Mac yet. (Emulation mode stinks)

Wednesday, December 24, 2003

Hope Springs Eternal

Spring - j2ee Application Framework

Here is the Spring framework. My pick of the week for interesting things you should look into.

Lions, Tigers, and Bears got nothing on HiveMind, PicoContainer, XWork, Avalon and Spring

Thomas Dyer
Sent : Wednesday, December 24, 2003 3:09 AM
To : "'Richard Hightower'"
Subject : RE: Interesting stuff we talked about.

| | Inbox


Tom Dyer write:

Rick,

Noticed you've looked at Pico Container. Check out the Spring Framework,
cool stuff. Here's a TSS article.

http://www.theserverside.com/resources/article.jsp?l=SpringFramework

Tom,


Tom is right. Spring is cool. It is not longer of matter of whether I will use an IOC container on my next project. It is a matter of which one.




Tuesday, December 23, 2003

What I have been up to

I am busy writing as of yet. I just wrote about applying TDD to Struts development with JUnit to test the model (MODEL), StrutsTestCase to test the struts Actions (CONTROLLER) and jWebUnit to test the JSPs (VIEW) and a Quick Start Tutorial to Struts.

I am really getting into the PicoContainer, Hibernate, Maven, Tapestry and XWork/WebWork. I think JSF will be the next thing that makes money. I wish there were more hours in the day.

Testing JSPs with jWebUnit

jWebUnit is another testing framework built on top of JUnit. It also uses HttpUnit, which is a framework for parsing HTML easily.

jWebUnit makes testing JSP easy by providing a high-level API for navigating web applications. Like StrutsTestCase, jWebUnit provides methods to verify and assert valid conditions. JWebUnit assertion methods relate to navigation and the HTML DOM for example, form entry and submission, validation of table contents, and many common scenarios.

TIP: The book Java Tools for Extreme Programming by Richard Hightower et al covered using JUnit and HttpUnit together to tests Servlets, JSP, Custom Tags and Filters. The chapter on HttpUnit is good background information for understanding jWebUnit. Using jWebUnit is much easier than using JUnit and HttpUnit together.

You can find jWebUnit at http://jwebunit.sourceforge.net/. You can download jWebUnit from http://sourceforge.net/project/showfiles.php?group_id=61302. Download the file jWebUnit-1.1.1.zip. Extract the file and put the jwebunit.jar on the classpath of your IDE project.

The jWebUnit framework depends on the HttpUnit framework so you will need to download HttpUnit. The HttpUnit web site can be found at http://httpunit.sourceforge.net/.
To download HttpUnit go to http://prdownloads.sourceforge.net/httpunit/httpunit-1.5.4.zip?download. Extract the zip file and put the following jar files on your projects classpath js.jar, junit.jar, nekohtml.jar, Tidy.jar, xercesImpl.jar, xmlParserAPIs.jar (found under jars) and of course httpunit.jar (found under lib).

Testing Struts Actions with StrutsTestCase

StrutsTestCase is a JUnit extension that allows you to test code that relies on the Struts framework. StrutsTestCase works in two modes: in container test, simulated container test. You can run StrutsTestCase test inside of a running J2EE container. This support is provided by StrutsTestCase̢۪s integration with Cactus. Cactus is a framework for in container unit testing. Cactus extends JUnit as well. StrutsTestCase also allows you to use a simulated container test via its Mock Object approach. You can find more information about Struts test case at http://strutstestcase.sourceforge.net/. You can find more information about Cactus at http://jakarta.apache.org/cactus/.

Using either mode, StrutsTestCase uses the Struts ActionServlet controller to test your Action objects, mappings, form beans and forward declaration. StrutsTestCase provides special assertion methods to assert for example that an action returned a certain forward.

You typically combine StrutsTestCase with Cactus when you have code that depends on J2EE container resources. For example, you have an Action object that depends on local EJB Entity bean. Suffice to say, it is a good idea whenever possible not to rely too heavily on container resources as your code gets tightly coupled with the J2EE environment and harder to test. The problem, with Cactus based StrutsTestCase tests, is that Cactus is hard to setup (but you only have to do it once), and the tests take longer to run than the Mock Object equivalent test.

On the flip side, container simulation—Mock Object based tests require that your action code is not tightly coupled with the underlying J2EE container. This requires a cleaner design and cleaner delineation between your model and the container. Typically, you can get a fairly clean design by using an Abstract Factory from you actions. Thus your actions never directly deal with J2EE, they talk to the Abstract Factory to get model objects. The Abstract Factory may in turn talk to the J2EE services like JNDI to look up and interact with EJBs, etc. Then for testing you create an Abstract Factory that delivers Mock Objects for testing. This is the approach I use. The advantage of using container simulation is you don’t have to deploy your code to the container to test it. In short, the reason to use container simulation is speed. Tests that take a long time to run don’t get run as often. TDD favors fast running tests.


Test Driven Development (TDD) is all the rage. Unlike most development fads this one has staying power. TDD gets its birth from the Agile Development community (http://www.agilealliance.com) and Extreme Programming (XP). Although originally espoused by XP, the main stream uses TDD, which requires fast running, automated tests. The purpose of TDD is to draw out what functionality is really needed, rather than what the programmer thinks is needed. Developing software in a J2EE environment can be fairly tough with its somewhat complex deployment requirements and dependencies on the J2EE container. Layer on top of that the Struts framework and its complexities, and fast automated testing becomes essential. Why essential you ask? It is essential because of speed! By the time, you can deploy, and smoke test a feature or bug fix, using TDD you could do it 4 times.

StrutsTestCase makes TDD possible with Struts.

Monday, December 22, 2003

Struts Training

Last week I was doing Struts training in Boston followed up by some architectural analysis of their current project. I ran into a real smart group. They need to incorporate agile development like TDD and pair programming. There were a lot of good ideas lurking in their framework. I added a few tricks to my bag of Tricks.

Sunday, December 21, 2003

jWebUnit

jWebUnit

If you know who I am, then you know I have used HttpUnit a lot in the past. I saw jWebUnit mentioned in "Java Open Source Programming", which covers XDoclet, WebWork and Hibernate (I highely reccommend getting this book).

I looked into jWebUnit. Pretty cool stuff. Please check it out. Just look at the first page. Very cool stuff.

I am going to start using jWebUnit where I used to use JUnit and HttpUnit together. jWebUnit builds on top of HttpUnit and JUnit.

This is taken from their site:
Compare this code sample....


package net.sourceforge.jwebunit.sample;

import junit.framework.TestCase;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;

public class SearchExample extends TestCase {

public void testSearch() throws Exception {
WebConversation wc = new WebConversation();
WebResponse resp = wc.getResponse( "http://www.google.com");
WebForm form = resp.getForms()[0];
form.setParameter("q", "HttpUnit");
WebRequest req = form.getRequest("btnG");
resp = wc.getResponse(req);
assertNotNull(resp.getLinkWith("HttpUnit"));
resp = resp.getLinkWith("HttpUnit").click();
assertEquals(resp.getTitle(), "HttpUnit");
assertNotNull(resp.getLinkWith("User's Manual"));
}
}



To this...


package net.sourceforge.jwebunit.sample;

import net.sourceforge.jwebunit.WebTestCase;

public class JWebUnitSearchExample extends WebTestCase {

public JWebUnitSearchExample(String name) {
super(name);
}

public void setUp() {
getTestContext().setBaseUrl("http://www.google.com");
}

public void testSearch() {
beginAt("/");
setFormElement("q", "httpunit");
submit("btnG");
clickLinkWithText("HttpUnit");
assertTitleEquals("HttpUnit");
assertLinkPresentWithText("User's Manual");
}
}

PicoContainer -

PicoContainer -

I read through the docs on this site. I really dig this type 3 Inversion of Control Container.

If you get a few minutes, check the site out. It only takes a few minutes to get what they are trying to do, and it makes so much sense.

Starbucks in Tucson

Most places I go, people think that Tucson is really backwards. The only Tucson they see is in the old westerns. Here is proof that we are not as wardsback as people think. BTW I can't fire a gun or ride a horse at least not very well.

Erik Hatcher at java.net

Erik Hatcher

What a terrible friend I am.... I just read Erik's stuff on java.net... it has been there for six months. It was fun haning out with Erik at JavaOne.

Cool stuff. Erik Rocks! I agree about the scripting languages. Why make JSR-223 Web centric? (I acutally care about scripting. I wrote a book on Jython and several articles on Jython, NetRexx, Bean Scripting Framework, etc. I hope scripting goes more main stream.)

I am happy to see JSP support other languages. Although with JSTL, I think it is a lot less of an issue than it was before. I guess this is mostlly to win over the PHP crowd.

Nutch sounds cool (see above link for more detail).

Rick's Resume

Rick's Resume

My resume use to show up second when you searched for "Rick Resume" in google.
Now it has dropped down to third. (I don't know why it was second.)

Anyway, my resume is a bit dated.

Saturday, December 20, 2003

Good article in this month's edition of Dr. Dobbs; porting Jakarta Lucene to J#

When I first saw J#, I just thought it was a dumb idea. My opinion, at the time, was why not just learn C# instead as it is close to Java. anyway. Then I read this article by Dr. Dobb about porting Jakarta Lucene to J#, and now I understand. In the article the author ports Lucene to J# and then calls into Lucene using C#. Pretty cool. The author had to use the GNU classpath project to make the Vector more like the current version. Weridly enough J# seems to be stuck in time at about JDK 1.1.5. If I was doing a new project in .Net, I would still use C# instead of J#, but I suppose if I had to port code to work in both environments, I would probably use J# like the article did. I can't wait till JDK 1.5, but it makes this type of porting moot (or it will in time).

Tuesday, December 16, 2003

Master the Tiles Framework with this tutorial....

The Tiles framework makes creating reusable pages and visual components easier. Developers can build Web applications by assembling reusable tiles. You can use tiles as templates or as visual components.

In some respects, the tile layout is like a display function. First you pass tile layout parameters to use. The parameters can be simple strings, beans, or tiles. The parameters become attributes to the tile and get stored in the tile's tile scope. For its part, the tile scope resembles page scope, and is less general than request scope. The tile scope lets the tile's user pass arguments (called attributes) to the tile.

Definitions let you define default parameters for tiles. Definitions can be defined in JSP or XML. Definitions can extend other definitions similarly to how a class can extend another class. Moreover, definitions can override parts of the definition it is extending.

The Tiles framework includes its own RequestProcessor to handle tile layouts as ActionForwards. Thus you can forward to a tile definition instead of a JSP if you install the Tiles plug-in.

If you are using Struts but not Tiles, then you are not fully benefiting from Struts and likely repeat yourself unnecessarily. The Tiles framework makes creating reusable site layouts and visual components feasible.


In this tutorial you will cover the following:


  1. The Tiles framework and architecture

  2. How to build and use a tile layout as a site template

  3. How to use tile definitions both in XML and JSP

  4. How to move objects in and out of tile scope

  5. How to work with attributes lists

  6. How to nest tiles

  7. How to build and use tile layouts as small visual components

  8. How to subclass a definition

  9. How to create a controller for a tile

  10. How to use a tile as an ActionForward

Good book... get it quick.... covers XDoclet, Hibernate, XWork, WebWork, Ognl, Jakarta Commons, SiteMesh and IOC, etc.

I just found this great book. Actually, I was told about this book at the Server Side Symposium in Boston. Funny that I am in Boston this week, when I finally bought a copy. (In case you can't tell by the title of tihs blog.... I live in AZ... BTW it is darn cold in Boston this week... nuff said.)


I've just read a few chapters and skimmed the rest of the book. This book is a classic. Hats off to the authors... Ara Abrahamian, Joe Walnes, Mike Cannon-Brookes, and Pat Lightbody. I can't wait to dig into this book into detail.

So far, all I can say is WOW! Good Stuff. Sucky title.... great book.

The book is called Java Open Source Programming by Wiley Press.

I am more of a Struts, Hibernate, XDoclet, Tiles, and JSTL EL person myself but it is good to learn more about WebWork, OGNL, etc.

Here is an update.... I have been digging in even deeper. I really love this book. I really the ideas behind XWork.

Friday, December 05, 2003

ArcMind, Inc.

Online Tutorials covering EJB, Web Services, WebShpere, Apache Axis, and more.

Tuesday, December 02, 2003

Accessing a Database from Struts using Struts Datasources

Accessing a Database from Struts

Datasource, DBCP documentation woes, suggested documentation fix


You need booth commons-pooling and commons-dbcp to get Struts Datasources to work, but this is not mentioned in the documentation and the required jar files do not ship with Blank.war. In fact in Struts 1.1., you also need Struts Legacy jar file as well. Of course, if you are using Tomcat then both commons-pooling and commons-dbcp ship in the shared folder but you do need to download them if you are using another application server. You do need to download them only f you are going to use Struts Datasources.

I think either
http://jakarta.apache.org/struts/userGuide/configuration.html#data-source_config
or

http://jakarta.apache.org/struts/faqs/database.html

should make note of this.

Here is a stab at it.

Struts Datasources require commons-pooling and commons-dbcp. The blank.war does not have commons-pooling or commons-dbcp. If you want to use Struts datasource, you will need to download commons-pooling and commons-dbcp from the following locations:

http://jakarta.apache.org/site/binindex.cgi#commons-dbcp
http://jakarta.apache.org/site/binindex.cgi#commons-pool


Download the above archives and un-archive them. Then copy the jar files commons-pool-1.1.jar, and commons-dbcp-1.1.jar into the WEB-INF/lib directory of your web application. Note that Tomcat 5 ships with commons-dbcp and commons-pool so you do not need to download and install commons-dbcp and commons-pool if you are using Tomcat.

In addition to the above two jar files, you will need to use the struts-legacy.jar jar file that ships with Struts 1.1. Copy the struts-legacy.jar file to the WEB-INF/lib directory of your web application.

This might be a moot point depending on how soon Struts 1.2 comes out, and if commons-pooling and commons-dbcp ship with Struts.

Rick Hightower
Chief Technology Officer
ArcMind
“Know the Next!”
http://www.arc-mind.com