Wednesday, October 03, 2012

Annotations and Maven

Thinking a lot about annotations and maven.... I love and hate Java annotations. I love them because you can put metadata and behavior hints on classes, fields, methods, and parameters.

I hate them because it ties you to framework which might have 20 mb of dependencies that you may decide not to use one day.

Compile time dependencies are great if you are the standard not so great if you are depending on some random project on github or googlecode which depends on different versions of jars you need.



- Posted using BlogPress from my iPhone

Location:Hobert St,Castro Valley,United States

Wednesday, January 28, 2004

Big Demo: Okay so I hit some milestones in the project. Today was the day to demo the product (in progress) to the customer. I give a few test runs before the big meeting. Everything works. During the meeting..... I run the demo (the most important part works), then another feature breaks with a problem I have never seen before. I run it again later, and can not reproduce the problem. I showed the customer the feature (working). I hate demos. The chance of something going wrong during a demo is so much higher than when not doing a demo. Why? Oh well. It is a work in progress.

JRoller seems to be down... I am back to using blogger.

Sunday, January 18, 2004

Moved to JRoller

JRoller

This blog has moved to JRoller. I am going to keep this blog site for a while. But for the latest and greatest blog stuff go to my JRoller account.

Saturday, January 17, 2004

SourceBeat - Open Source Documentation for Eclipse, Tomcat, Struts, Apache, Perl and more...

SourceBeat - Open Source Documentation for Eclipse, Tomcat, Struts, Apache, Perl and more...

Hey... I got mentioned on this site! Free plug for me.

"SourceBeat is the first publisher to create always updated open source technology books, written by expert authors such as James Goodwill, Rick Hightower, Bill Dudney, and many others. Utilizing our patent-pending "OpenBook™” process, you are always sure of getting the best information regarding the open source topic."

Friday, January 16, 2004

I tried JRoller out.

Hmmmm.....

I may switch.
I just bought four books:

JUnit in Action written by Ted Husted and Vincent Massol.

XDoclet in Action by Rickard Oberg, Craig Wall, and Norman Richards.

Expert One-on-one J2EE design and Development by Rod Johnson. There are no books on Spring yet, but I heard much of the Stuff that is in Spring is covered in this book.

Patterns of Enterprise Application Architecture by Martin Fowler.

I almost bought Contributing to Eclipse: Principles, Patterns, and Plugins by Erich Gamma, Kent Beck, but I went way passed my monthly book allowance already.


I think I have every book Kent Beck has written. I like his writing style, and his message. It is on my wish list.

I am currently writing a book. I've written several hundred pages so far. In fact, I need to get back to my writing now. L8er

TheServerSide.com - Kito Mann Interview

TheServerSide.com - Kito Mann Interview

Kito is the Man!

Good interview. I will be buying his book.

between the lines: For whom do those e-bells toll? Ask promoOrder

between the lines: For whom do those e-bells toll? Ask promoOrder: "'The reason I think eBlox will succeed is we're self-funded,' says CEO Brent Buford. 'We don't have those outside investors telling us we have to perform a certain way. In the case of PromoFuel, we hit our stride right when the economy went down the tank.'"

My old boss tells it like it is. Venture Capital stinks. You don't want somebody who made their money seeling coin operated laundry machines how to run your software company.

Software Development Conference and Expo West 2004

Software Development Conference and Expo West 2004

I'll be speaking at SD West on extending Struts and J2EE development with Ant.

Extending Struts
Description: Okay you think you have mastered Struts, but you wish it could just do this one special thing? This session shows you how to go beyond the Struts basics to extend the framework to fit you needs. Struts was designed to be extensible. Learn how to extend it. Advance Struts topics about extending the framework using Struts plugins, and extending the Action Servlet, Custom Actions, the RequestProcessor, and more. This is an advanced topic that assumes previous knowledge of Struts.


J2EE Development with XDoclet and Ant

Time/Date: Friday (March 19, 2004) 10:30 am - 12:00 pm
Track: Java Programming
Format: Class
Level: Intermediate/Advanced
Description: This class covers developing J2EE components with XDoclet. XDoclet can drastically speed J2EE development by generating component support files by embedding meta data in what looks like JavaDoc tags of the component implementation. This class will also demonstrate developing Custom Tags, Entity Beans, Session Beans, and Struts Actions with the assistance of XDoclet combined with Ant.

Thursday, January 15, 2004

Erik Hatcher - Blog

Thanks Erik (Erik Hatcher - Blog). Erik is always so way ahead of the curve. I have to check what technology he is working with so I know what technology I will be working with in 6 months. It was fun working with Erik at eBlox.

logic:present and logic:notPresent good for model 2 but use JSTL instead

The and tags check to see if headers, request parameters, cookies, JavaBeans or JavaBean properties are present and not equal to null. You can specify the string which can be a cookie, header, request parameter or bean property by using the attributes cookie, header, parameter, or name & property. Additionally you can check to see if the current users is in a certain role using the roles attribute (this integrates with the J2EE security model).

TIP: both the and fits really well in a Model 2/MVC architecture. You can allow the controller, i.e., your actions, to decide which objects to map into scope based on executing business rules of your application model. The JSP page, which should have very little logic in it, will just check to see if an object is in scope and if it is in scope then it displays the object. This way if the underlying business-rules of the model changes, it does not affect the JSP code. The JSP never knows why it's displaying object just if that object is present then it should display that object. It's up to the controller to decide which objects to map into scope after executing business rules on the model.


You can do the same thing as the logic:present and logic:notPresent tags using JSTL. New projects should use the JSTL equivalent.

EL would be foo!=null
or not empty foo

Best Struts Course, Struts Training, Struts Consulting

Wednesday, January 14, 2004

A Sleepless Night in Tucson

A Sleepless Night in Tucson

I read my blog entry from last night, and I realize it had a little too much bile in it.

Tuesday, January 13, 2004

Amazon.com: Books: Professional Jakarta Struts

Amazon.com: Books: Professional Jakarta Struts:

Sooyoung Park write a review as follows.....


"I have two gripes with this book. First, it's really a shame that the authors didn't take the time to include information about Unix/Linux installation and configuation since the vast majority of us will be deploying on those platforms, if not developing on them outright.


Any self-respecting Linux/Java developer can translate instructions from Windows/DOS into Linux, if not they should not be using Linux. We also don't have instructions for AIX, Solarix and HP-UX.


Secondly, the book is a little behind the curve regarding Struts 1.1. For example, the use of Struts tag libraries has been considerably simplified and the file upload example on page 391 uses the deprecated FormFile class instead of Jakarta FileUpload. It's only natural for APIs to change, but if you plan on buying this book, be prepared to spend some additional time on the Jakarta web site. "


Is not! Check out the javadocs from the nightly build for FormFile. It is not deprecated. The book does not cover Jakarta FileUpload directly as it is used under the covers by Struts. Look a little further and you will find CommonsMultipartRequestHandler.CommonsFormFile. This class implements the Struts FormFile interface by wrapping the Commons FileUpload FileItem interface.

So in short.... You don't know what you are talking about. Spend some time on the Jakarta web site before you criticize me for not spending time on the Jakarata web site.

Amazon.com reviews are a farce.

Amazon.com reviews are a farce.

Who says there is no drama in our industry?

I've been reading WSI profile spec. until my brain started bleeding, when I found the above link in an unrelated track of thinking. If you like controversy, and heated debated then you will love the above.

I hardly every buy books based on their Amazon review. I may be old fashioned but I usually go to the book store and read chapters from the book first. I spend at least an hour reading through a book before I buy it. Unless, it is the only book on the topic.

I got my first endorsement on www.linkedin.com

I got my first endorsement on www.linkedin.com

"I worked with Rick at eBlox - he literally saved the company from a sure death and he documented much of our experiences in the fantastic Java Tools for Extreme Programming book. Rick is a jack of all trades, and master of most - I wish he was on my team now!" -- Erik Hatcher

If you are going to get an endorsement..... getting one from Erik Hatcher is a good thing. Erik Hatcher is the Ant, Struts, and WebDevelopment guru.

I dig linkedin.

Struts book doing well: Professional Struts

For a while the first edition of our Struts book was outselling the second edition. It sure did not help that the first edition was under a Wiley imprint and the second edition was under a Wrox imprint, and they changed the name of the book. My understanding is that Wiley bought the rights to Wrox name and their best selling books when Wrox went out of business. Now the book is third on Amazon (out of all Struts books), which is not too bad considering the Orielly's book and Ted Husted's book are number 1 and 2. For a while, the book was second on bookpool right after the Orielly book, which blows my mind. Now the book is no longer second on book pool, it is has dropped. This could be because bookpool is out of stock! Come on. You may wonder why I care. Mainly, if I am going to spend time writing a book, I want people to read it. Perhaps this is vain. The biggest complaint about the book seems to be that it does not cover Linux installation. Hey, if you can not translate the Windows instructions to Linux instruction in your head, then you probably should not be using Linux. We expect more from Java/Linux developers.

Monday, January 12, 2004

The Artful Blogger: Struts jobs in London... Struts jobs in the US.

The Artful Blogger: Struts jobs in London

Hmmmm.... this made me think.... what about the US?

I checked Dice....

370 Struts jobs in Dice.

1 WebWork job in Dice. (0 for WebWork2)

The momentum still seems to be behind Struts. I think Struts and JSF is the ticket (Struts + JSF). Hmmmm....

Struts vs. WebWork

Jason Carreira

Another WebWork vs. Struts comparison.

Struts has great IDE support. WebWork has some very cool features, but none that cannot be added to Struts. There are parts of WebWork I really like, but everywhere I go, the client is using Struts. Hmmmmm.....

Kris Thompson's Weblog

Kris Thompson's Weblog

WebWork vs. Struts comparison.

rebelutionary: Open Source FUD - The Verge Framework

rebelutionary: Open Source FUD - The Verge Framework
To rebelutionary (a.k.a. Mike Cannon-Brookes),

I agree.

I don’t know anything about the Verge framework. It might be the greatest thing since sliced bread, but Struts and WebWork are established and does the world need another front controllerish framework?

How many IDE’s support Verge?
How many books are written about Verge?

You probably don’t remember me. But, we met at TheServerSide.com.

I read your book: “Java Open Source Programming”.

I must say I really dig it. I’ve used most of the tools you cover before, except WebWork and XWork (a bit of a Struts guy…pays the bills).

I had a hard time with the XWork chapter, but I did a little research online, and I got it. The second go round made more sense after doing a little research.

Great job. I like the ideas and design of WebWork. Give Joe Walnes.... my regards.

--Rick Hightower


Sunday, January 11, 2004

Dragon NaturallySpeaking.

I just got a new toy. I got a new copy of Dragon NaturallySpeaking. Dragon NaturallySpeaking allows me to write faster (hopefully). It's not perfect, but it is pretty darn cool. So far I taught NaturallySpeaking to recognize words like:
ActionForm;
DynaActionForm;

Work is pretty busy lately. For that I am thankful, but it means that the writing assignments that I have are going to take longer. I just got back from the cold weather. My first day back in Tucson was 75°F--quite a change from last week.

I got a lot of consulting work lately. I should be busy for quite a while which is good. Most of the work involves Struts and Hibernate. I have a new assignment that involves maven. I really enjoy working with maven.

It is good to be busy.

By the way, I wrote this blog entry with Dragon NaturallySpeaking. I had to make a few corrections. It did not understand a word blog. It has a training mode. But I have not trained it to understand the word blog yet. You really have to announciate your words, when you're using Dragon NaturallySpeaking. You are supposed to corrected whenever it makes a mistake and train it to listen to the way you speak.

It is supposed to improve as you use it and continue to train it. It'll take a while for it to work the way I want it. Already it is useful.

Thursday, January 08, 2004

MVC for Struts Smarties

MVC for Struts Smarties
Mastering MVC and Model 2 with Struts

Struts promotes a Model 2 / MVC architecture. Essentially, Struts architecture is based on the J2EE blue print for Java, which heavily promotes using MVC. It has been said that Struts is the instantiation of the J2EE Blueprint’s view of the Web Tier.

TIP: Read the J2EE Blueprint at http://java.sun.com/blueprints/guidelines/designing_enterprise_applications/index.html.

Many times application can have more than one type of client (e.g., web client, and rich GUI client). For client independence and testability, it is good to develop your applications where the application data and business rules are separated from a particular client implementation. In order to adapt the application to multiple clients and to organize the code into separate areas of concern, you typically implement the systems using a variation of Model-View-Controller Architecture (MVC).

MVC is an open architecture with multiple tiers. The Struts framework uses a variation of MVC that was adapted for web development called Model 2. The following sessions considers MVC/Model 2 and its ramification on Struts usage.

WARNING: Java promotes object-oriented programming, but does not enforce it., i.e., you can create non OO code in Java. Similarly, Struts promotes MVC / Model 2 architecture, but does not enforce it. Making Struts foolproof with regards to MVC is difficult as foolish developers are ingenious. To get the best out of Struts, you need to know MVC / Model 2.
Model Tier

The model is the application data and the business rules of your application. The business rules are the rules for changing your application data. Many types of applications can share your application’s model. The model code should not be dependent on Struts, or the JSP/Servlet API.
The Struts framework provides no model classes per se. All application should have different models.

TIP: The Struts framework does not provide any model objects. Your model is specific to your application. Often developers develop their model with EJB, JDO or Hibernate. The model consists of the persistence layer, and the business rules for modifying the persistence layer.


View Tier
The view tier is what the end-user sees. The view displays parts of the model to the end user. Different types of clients (web client, rich GUI client) have different view. The view should never modify model data directly, nor should it interact with business rules of the model.

The Struts framework does not specify a particular view technology. The Struts framework does provide many JSP custom tags to aid in developing with JSP tags. You can also develop views with other technologies like Velocity (which has Struts tools), JSF and XSLT. Struts is fairly view agnostic.

TIP: Many of the JSP custom tags that ship with Struts are essentially deprecated in favor of their JSTL equivalent (c:forEach vs. logic:iterate). Other Struts custom tags are key to Struts development like html:form.

Controller Tier
A controller acts like the glue between the model and the view. The controller defines the flow of the application. It interprets events from the user (user gestures), and acts like the mediator between the view and the model. It parses the user gestures into actions it performs on the model. Different types of clients require different types of controllers. In Struts, the actions (Action), ActionServlet and config objects (created from struts-config.xml), act as the controller.

The controller accepts user events from the view. In a Web interface, the user events are page loads (HTTP GET) and form submissions (HTTP POST) requests.
To help separate the Model from the View, the controller should convert the request data, scoped beans, and request into business actions. The Struts framework does part of this for you. You do the rest of the conversion as your write action (Action) that act as intermediaries from the web request to the model.

It is the controller job to select the next view to display; this is part of managing the flow of the application. The actions that you write return an ActionForward to the next view. Thus the ActionForward represents the next view in the system. And, it is the job of the actions, you write to return the next view. In the actions you write, you typically interact with the model’s business rules, look up model data, map the model data into scope (request, session, etc.) and then select the next view so the view can display the model data.

Rules for writing proper MVC application with Struts

Rules for the View Tier
The view should never select the next view. This means that the JSP files should never use jsp:forward, logic:forward, logic:redirect, or core:redirect (JSTL) to change the view to a new JSP. Your actions should select the next view by returning the appropriate ActionForward.

Try to only use stupid JSPs. A stupid JSP is a JSP that does not have a lot of logic. Try to limit the logic to looping through collection of data, and displaying objects if they are in scope (logic:present and core:if value=”not empty…). Often times I see JSP errantly sorting data, or checking with a model to see if a part of the page should display. Instead let the Action sort the data before it gives it to the JSP, and let the Action decide if a model object(s) needs to be display by interacting with the business rules of the model. JSP should not know why it is displaying an object if it is there display it. That way if the business rules for displaying the tag changes, the JSP does not change.

A funny thing happened. They added custom tags to simplify JSP development, and remove Java code (Java Scriptlets and Expressions in the JSP) from the JSP. Then people started writing what they use to write in Java in logic custom tags. This helped, but the maintainability problems remained. The key is not only limit the Java code in a JSP, but to limit the logic in the JSP. Keep your JSPs simple and your web application will be a lot more maintainable.

If your JSPs start to have too much logic (Struts logic:* tags, and JSTL core:* tags), move that logic into the action. If your are worried about too much code in your Action, use Action chaining. For example, you could have an Action that sorts the data that another Action put into scope then forward to the JSP.

Rules for the Controller Tier
Actions should be small. Actions should never do JDBC directly. In fact, Action should never talk to EJBs directly, or Hibernate, or etc. Action should instead only talk to façade facets of the model. If you are using Session Facades (EJB), use delegate objects (wrapper object) so that the Action does not talk directly to the EJB. Limiting the Action to only talk to a façade of the model, helps keep the Action testable with unit tests. Conversely, tying the Action to some underlying technology couples the Action to that technology and makes the Action harder to test.

Action should never implement business rules, or perform complex calculations. The Action should delegate those tasks to the model.


Rules for the Model

The model should be completely divorced from the controller. The model should not be dependent on any class in the Struts hierarchy. The individual model objects should be hidden behind a façade.

TIP: A great OO guru once said that the great thing about objects is that they can be replaced. As it turns out, the Controller is more testable if it is divorced from the model implementation. This allows you to substitute stubbed out objects that return hard-coded results needed to test the controller logic in you actions. There are several ways to do this. The controller code (actions), could look up Model facades in a registry, and instantiate them. You could also use an IOC (Inversion of Control) container like Spring, PicoContainer, HiveMind, or XWork. The Spring et al framework is beyond the scope of this discussion, but look for a chapter on using the Spring framework plugin with Struts. The best discussion of IOC, I’ve seen is at http://www.picocontainer.org, which is a type 3 ICO container.


Best Struts Course
New JSF Course

It is official.... there is a developer need uptick! It seems like a lot of projects are ramping up!

Wednesday, January 07, 2004

Kris Thompson's Weblog: Ken's Predictions for 2004

Ken has a list of prediction for 2004.
Kris Thompson's Weblog

His list has inspired mine....
My predictions....

1) Struts will continue to make gains because of the IDE support for Struts.
2) Struts will integrate well with JSF.
3) JSF will be adopted as fast as Struts was.
4) Struts will integrate well with Spring.
5) Projects that use Struts + JSF + Tiles + Spring + Hibernate will be the most common web applications
6) Hibernate will win over EJB CMP/CMR and JDO (continue to win)
7) WebWork style feature will make it into Struts

This will be the year of JSF, Hibernate, and Spring.

JSF is to JSP as ASP.Net is to ASP. JSF will rule supreme.
Hibernate will continue to be the OR mapping tool of choice.
Spring has sprung.
A cottage industry of JSF component development companies will spring up to create GUI Widgets!

GUI Widgets for sale!

JAVA™ ADVISOR®: Professional Jakarta Struts: Advanced Action Classes - - ADVISOR.com - -

I found my chapter on someone elses blog... thought I would add it to mine....
JAVA™ ADVISOR®: Professional Jakarta Struts: Advanced Action Classes - - ADVISOR.com - -

Cold is too weak an adjective to describe this weather..... Brrrrrrrrrrrrrrrrr.... Maven Guru

I have met the Maven guru! He has done things with Maven that you can only imagine. He has written 6 Maven plugins and created something similar to AntHill, but for Maven. WOW! Cool stuff. We are going to work on the next version of MavenHill together. Cool job.... Cold climate.

Musings, Shock Bloggers on the rise, Good Enough Development, TDD, Loving Software Development again (AOP, IOC, TDD, IF)

I am sitting on a plane flying to the brave, north mid-west.... waiting to get to the 9 degree weather that awaits me. I just saw that new Denzle Washington movie (Out of time... I think). Good movie.


Things have been going really well. I am happy with the progress of work. I've got more work than I can handle, which is a good thing. I am looking forward to speaking at the "No Fluff Just Stuff Software Symposiums" this year.

Mussing...
I've been thinking a lot about JBoss, JMX and JMS as of late (today).


I have a IBM WebShpere project that I need to get started on next week too. IBM WSAD 5.1 is pretty kick butt. Java IDEs are really comming into their own.

A year ago, I was getting kind of sick of Java and J2EE (bored really). Now with JSF, AOP frameworks, IOC containers, great OR mapping tool, advances in TDD (JWebUnit, MOckObjects, etc.), it is all exciting again. Thanks guys... my work is fun again.


I love TDD. I like developing that way. I like writing quality software. I have been test addicted for a while (1996), but have recently taken it to a new level with TDD (thanks Kent Beck for you TDD book; thanks Vincent Massol for explaining the real value of Mock Objects).


I hate pontificating, arrogant developer blogs. I don't like the tone of some developer blogging. I don't like bile(ing) someone. I don't like when other people do it either. I love blogs and even read biles, but don't like it, but am attracted to read them.

I don't like when people take an absured point of view just to get heard. I think I am going to coin a new term for this.... Shock

Bloggers. (kind of like Shock Jocks....)
Hmmmmmmmmmmmmmmm..... How about Shog Bloggers?!

I personally think that everything has a balance, even quality. "No Margin. No Mission." is my mantra! Don't get me wrong. I like writing quality software, and think we ought to be craftsman. But not all projects have to be a work of art... a lot of projects just have to work and provide business value. I am a strong believer of "good enough"; the value of the project has to exceed the development costs (Return on Investment). I feel developers often go overboard with whatever is the newest latest thing or trend. My main focus is to provide value. What can I do to provide business value as soon as possible and as cheap as possible. Don't get me wrong, I am not suggesting shoddy work, but I am suggesting doing easy jobs quickly.

Don't get me wrong....I spend too many hours trying to improve my craft (just look at my bookshelves and ask my wife), but not at the expense of making my clients money.


Yes! It all comes down to money. Business value = money. I want to provide the best solution for the time available. There are other costs like oppurtunity costs. Sometimes it is more important to get it done. If you don't get it done in a timely matter, there will be no second chance. Sometimes you just got to get it done. There is time for improvement later. Keep it simple. The simplest solution that fits the customers needs (sometimes the simplest thing is still complex that is what makes our jobs interesting).

Tuesday, January 06, 2004

Good couple of days.... I like JBoss.... MyEclispe ROCKS!

What a great couple of days..... I just spent the last two days in Phoenix. I was called into do an architectural analysis and provide mentoring for this future, strategic application.

While I was on vacation in Colorado, I got called to go to Phoenix and do some Struts Consulting and some Struts Mentoring .... it turned into being a lot more than that. I only had two days to spare as I had previous commitment doing Maven Consulting and they needed someone ASAP. The engagement ended up being a lot more than Struts Consulting and some Struts Mentoring . We did a lot of of work with JMS. I knew JMS well but it has been a while since I used it--turns out I was not very rusty. (I worked on a JMS implementation in the past for a EJB container company. And, I wrote a JMS course as well as courses that uses MDB. And, I have used JMS on several project... just not recently).

They discussed their application for about 1/2 day. Then they discussed their marketing goals and vision. It was good background. I was very familiar with their domain (too familiar).

They wanted advice about how to use J2EE/Struts/JMS/EJB/MDBs/MOM. With my previous experience in their particular vertical and my knowledge of the technologies, we were off to the races. I convinced them to use Hibernate for their application instead of EJB CMP/CMR. (This is the nth customer who I have convinced to use Hibernate). (BTW I love Hibernate... Gavin King rocks! The funny part of this is that we were an early adopter of EJB CMP/CMR, and I even spoke about EJB CMP/CMR at JavaOne last year as well as wrote about it at IBM developerWorks, but now I prefer Hibernate. I still use EJB CMP/CMR every now and then when customers want me to, but prefer Hibernate.)

The architecture analysis went so well the first day that we decided to write a prototype the second day. We quickly had a prototype up and running, which consisted of Struts based web app uploading files (using FormFile). The web app would send a notice that the file was uploaded using JBoss JMS. We had an MDB listening to the queue which would then submit the job to be processed... (can't say anything more that).

They are a JBoss shop. I have used JBoss before, but usually use WebLogic or WebShpere. It is not that I do not like JBoss, it is just that most of my clients use BEA WebLogic or IBM WebSphere (I use whatever I get paid to use). I am personally partial to Cuacho Resin. However.....

I found working with JBoss JMS a joy after I convinced them to buy the documentation. ;) We were setting up queues in no time. They recently bought copies of MyEclipse, which is a suite of plugins for Eclipse and J2EE (with XDoclet support). It was a little frustrating because they did not know how to use MyEclispe well (they just got it), and I did not know how to use it at all. But after some trial and error, I found MyEclispe (we found) to be awesome. I am a MyEclipse believer; the XDOclet support is awesome and works well with Hibernate. We started implementing the domain in Hibernate.

It seems like a great project. I hope I get to work on it some more (during the implementation phase). They are still in the planning stages. My contact told me that "You guys exceeded our expectations with your knowledge of the technology (JMS, Struts, J2EE, etc.) and our domain." It was a good feeling moment. Now I am sitting in an air port on my way to another client site. Business is good and busy. At this next client, I am accessing creating a build system (with custom plugins) in Hibernate. Seems like a fun project.

I am going to a place that has 0 degree weather. Brrrrrrrrrrrrrrr......

Sunday, January 04, 2004

Java buzzwords :-)

List of Free Java Books!
Java buzzwords :-)

Feedreader | new.media.tool

I wanted a blog aggregator and Erik suggested Feedreader | new.media.tool.

So far I added Erik's blog and The ServerSide.com....

Pretty cool.... Reading blogs is now like reading email.

J2EE BluePrints: The Web Tier

I find that many people usnig Struts fail to grasp concepts in the blue print:
J2EE BluePrints: The Web Tier


Before one can grasp Struts, you have to grasp Model 2 and MVC. A good source for this is right from the source:

MVC - Model 2

JSF and Struts

Apache Wiki: StrutsMoreAboutJSF:

A great quote from Craig:

"An additional lesson, though, is for the Struts developers ourselves. We were one of the pioneers in the webapp framework space, and have arguably been the most successful. But we were not alone. Indeed, my spreadsheet of various implementations of UI component and web app framework architectures (just the ones in Java) has roughtly fifty entries in it. That's way too many for tools to support; it's way too many for potential users to evaluate; it's way too confusing to the market; and it's way too weak for Java as a whole
in the face of a determined competitor who feels threatened by the success of Java technologies at every turn. "

About Struts and JavaServer Faces [forward-looking]

About Struts and JavaServer Faces [forward-looking]

"
While things can always change in the future, many JSR-127 expert group members consider high quality integration with Struts to be an important success factor for JavaServer Faces to be accepted. Therefore, I do not expect that JSF will evolve in ways that make this kind of integration difficult or impossible.

"

Regular Expressions

Here is a good reference for using the regular expression library that ships with Java: Regular Expressions

Steve Ramsay's Guide to Regular Expressions

Steve Ramsay's Guide to Regular Expressions is a good reference for regular expression when you need to review.

rick hightower dot com - 2003: Rick's Resume

I had to update my resume. A company just found me through my resume (rick hightower dot com - 2003: Rick's Resume). They found that I worked at ArcMind by looking at my resume and web site, which is funny since my resume did not mention ArcMind--now it does. ArcMind got a new contract out of the deal.

I was just reading in InformationWeek that job oppenings for software developers has gone up 40% in the last few months (mostly in Silicon valley and Washington DC). It seems that the homeland security department has a lot of IT projects going on according to the article. Business has been good for us.

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

Friday, November 28, 2003

My first Fan

I got an interesting email (Subject Fan) today as follows:


Dear Mr. Hightower,

I am truly impressed by your technical achievements. I have been looking for (advice on) my career ...
My ambition is to be close to what you have done in your career....

I already have a head start with an Engineering degree in Electronics, and a Master's Degree in CS. Also, I have about 10 certifications including J2SE 1.4 and SCWCD (with 93%).

I am eagrly waiting for your response.

NAME_WITHHELD_TO_PROTECT_THE_INNOCENT
Indiana, USA.



I doubt I will get email like tihs very often so I suppose I should enjoy it or something.




I admire Martin Fowler, Kent Beck, Robert Orfalli, James Gosling, Drew Davidson, Erik Hatcher, Dan Harkey, Nick Lesiecki, Grady Booch, Peter Coad and many more. I have had the pleasure of meeting and talking to a lot of folks on my list in person, though I doubt any of them remember me. I worked with Erik, Nick and Drew at eBlox so they have to remember me. Everyone I met was extremely nice.



My first Fan

I got an interesting email (Subject Fan) today as follows:


Dear Mr. Hightower,

I am truly impressed by your technical achievements. I have been looking for (advice on) my career ...
My ambition is to be close to what you have done in your career....

I already have a head start with an Engineering degree in Electronics, and a Master's Degree in CS. Also, I have about 10 certifications including J2SE 1.4 and SCWCD (with 93%).

I am eagrly waiting for your response.

NAME_WITHHELD_TO_PROTECT_THE_INNOCENT
Indiana, USA.



I doubt I will get email like tihs very often so I suppose I should enjoy it or something.




I admire Martin Fowler, Kent Beck, Robert Orfalli, James Gosling, Drew Davidson, Erik Hatcher, Dan Harkey, Nick Lesiecki, Grady Booch, Peter Coad and many more. I have had the pleasure of meeting and talking to a lot of folks on my list in person, though I doubt any of them remember me. I worked with Erik, Nick and Drew at eBlox so they have to remember me. Everyone I met was extremely nice.



My first Fan

I got an interesting email (Subject Fan) today as follows:


Dear Mr. Hightower,

I am truly impressed by your technical achievements. I have been looking for (advice on) my career ...
My ambition is to be close to what you have done in your career....

I already have a head start with an Engineering degree in Electronics, and a Master's Degree in CS. Also, I have about 10 certifications including J2SE 1.4 and SCWCD (with 93%).

I am eagrly waiting for your response.

NAME_WITHHELD_TO_PROTECT_THE_INNOCENT
Indiana, USA.



I doubt I will get email like tihs very often so I suppose I should enjoy it or something.




I admire Martin Fowler, Kent Beck, Robert Orfalli, James Gosling, Drew Davidson, Erik Hatcher, Dan Harkey, Nick Lesiecki, Grady Booch, Peter Coad and many more. I have had the pleasure of meeting and talking to a lot on folks on my list in person, though I doubt any of them remember me. I worked with Erik, Nick and Drew at eBlox. Everyone I met was extremely nice.



Tuesday, November 11, 2003

Mock Object Testing: A new respect for it

I have a new found respect for Mock object testing. I was just on this project that had a fairly laborius deploy process. I found mock object testing helped me write tests that I could run more often. I found myself more productive as I did not have to wait for the server to start up before I started writing tests and code.

Cool project, a lot of fun, Tiles, lots of tiles (Struts chicken richness)

I worked on this project, recently, that was quite a treat. The application was a web application that was quite rich with functionality. I was charged with writing a menuing system that would only display certain menus depending how the user was logged in. The system integrated and extended the J2EE security model. I wrote a Struts extention (plugin) for the menuing system. The menus were stored in an XML file. I used the Jakarta commons digester to read the XML file. I dig commons. I used the tiles framework to render the menus. I wrote a tile controller to manage the state of the menu. I wrote a Struts plugin that used the digester to read the menuing system.

Later I worked on a pagination piece and a embeded Search piece. I used Tiles for both. I dig Tiles and Tile controllers.

Sunday, November 09, 2003

Note to self.... write down the user name and password

I installed this new server software. I am doing a course port to a new platform. I spent some time installing and configuring this server. I returned to it in a few days, and I cannot remember the blessed username and password. It is okay. I set it to something I would not forget, but I did forget. Grrrrrrrrrrrrr................

So now I uninstall and reinstall.... This time I will write it down.

1/2 hour later. Now that I have uninstalled an reinstalled. I realize that the install never asked me for a username and password. Great.

New Company...... Arc-Mind.... Know the Next!

It is official. I started a new company last week. People (mostly relatives) ask me if it is scarry. Mostly... it has been exciting. I feel a bit giddy. eBlox is designing the look and feel of the site. I decided early on that I wanted a professionals designing the look and feel and logo for the site. Part of growing up is knowing your weaknesses. I know that I have no artistic ability. I did not want the site to look like.... Well, you get the idea. eBlox creates the best looking sites. They have one more awards than most design companies I know. And, they are friends.

I'd like to announce to anyone who cares that I am available for work. I am pretty well booked for the next few months, but I am sure I can fit some more work in. :o)

Saturday, November 08, 2003

Fr33D0M

As usual Erik beat me to it.

Erik wrote...

Yup, I resigned my full-time day job position.
But rather than taking a new job, I'm going to continue contracting with them on a half-time basis. And just so you readers don't get the wrong impression, don't go write a book thinking you can quit your day job and rest easy on royalties. I'm taking a huge financial hit as well as a fairly sizeable risk. But risks make it all worthwhile.




My last day was last Monday. I gave a one month notice too, and Monday was the last day. I don't have a new job. I did start my own company. I do have a *lot* of contract work. I am working on another book too. And, I am working as a consultant to my last company on a part time basis. How is that for being in sync. with the Hatch!

I worried for a long time. I have had a lot of success at all the companies I have worked for. And... this has been a slow progression going from smaller company to smaller company.... And then finally on my own! It feels good! Really GOOD!


Friday, November 07, 2003

Wired, then Tired: A good coding session ends the week on a positive note.

I worked late Thursday night, and I am tired. I started refactoring this one piece that I have been working on. I kept refactoring it until I could reuse the pieces I needed on a set of similar pieces. It was fun. The more I refactored, the more oppurtunties there were for refactoring. It was nice to have a set of automated tests to make sure I did not break anything as I was making fairly large changes to the system. I came out with a lot of good abstractions. I ended up using a template method base class that dicated the overall flow. Then a set of higher level abstractions for the template method base class to use. The subclasses had factory method to create specific instantiations of the higher level abstraction. I made a lot of progress and the more progress I made the less I felt like going home. By the end of the session, I had got a lot further than I had imagined. It was a blast. I live for coding sessions like that. When I started I had one working piece that implemented a user story, when I was done I had implemented five user stories that had similar work flows.

I love speaking, writing and teaching, but I must admit I enjoy coding the best. Especially when I get in the zone! I wish all days could be like last Thursday.

Tuesday, November 04, 2003

Read-Rite Corporation goes away... a sad day!

Goodbye old friend! I'll miss you. I got my start at Read-Rite. I did not
learn to program there, but I sure honed my software development skills there. I will always
remember: Dave, Balaji S., Vince R., Rick K., and Peter B.




On or about June 17, 2003, Read-Rite Corporation ceased operations and filed for Chapter 7 bankruptcy in the United States Bankruptcy Court for the Northern District of California, Oakland Division, Case No. 03-43576 RN-7.

Please send inquiries concerning Read-Rite Corporation to:
Tevis T. Thompson, Jr.
Trustee for the Bankruptcy Estate of Read-Rite Corporation
c/o Jeremy W. Katz, Esq.
Pinnacle Law Group
425 California Street, Suite 1800
San Francisco, CA 94104

Struts and IBM developerWorks


DeveloperWorks has been covering Struts for a long time and has quite an array of timely material on Struts.


  1. Struts, an open-source MVC implementation

  2. Struts and Tiles aid component-based development

  3. Struttin' your stuff with WebSphere Studio Application Developer, Part 2: Tiles

  4. Integrating Struts, Tiles, and JavaServer Faces

  5. Architect Struts applications for Web services

  6. Go-ForIt Chronicles, Part 19: Struttin' your stuff with WebSphere Studio





I particularly liked the Go-ForIt Chronicle series and the Integrating Struts, Tiles, and JavaServer Faces.
If you are jonesing for some Struts information, IBM developerWorks is the place to get your Struts fix.



Oh yeah... don't forget to get a copy of James and I's new Struts book: Professional Struts.
It is the most up to date Struts book, and it covers the Validator Framework and the Tiles Framework in detail.

Thursday, October 30, 2003

This year is winding up.... it has been a good year

It's been a good year.

This last month. I've been doing a lot of work with Struts for this client. There system is well designed and thought out and a real pleasure to work on.

I just wrote a pagination tile/tile controller. Earlier I wrote a navigation system, essentially a Struts plugin that does secured menuing. (Only shows menu's user are allowed to visit.)

I've also been helping to resolve build issues and J2EE environment issues (classloader, jars in the wrong location, etc.) In addition, I have been doing a lot of mentoring. Developers come to me with their Struts/J2EE questions and we figure things out together. It helps "to have been there and done" that many times before.

The navigation system worked really well until we integrated it wtih the real security system. There was some integration pain and some late night coding sessions, but in the end it works really well. It was architected well.

I wrote a replacement for LookupDispatch that allows multiple buttons on the same page to have the same label.

I spent a fair bit of time wrestling with CSS to make buttons look like links and work in both Netscape 6.22 and IE 5.0 and higher (the requirement for the project).

We were able to avoid requiring JavaScript and still meet the fairly rigid GUI guidelines.

More to come.....

Next time I will write about the joys of Mock Object testing...

I've moved on over into the Mock Object testing love fest crowd, and I have started to not rely on Cactus so much.

Tuesday, October 21, 2003

IBM Web Service Wizards

Rick Hightower, CTO at Trivera Technologies LLC (www.triveratech.com ), a training and consulting firm helping companies with Web services implementations, said that he's impressed with the wizard technology in IBM's new WSDK 5.1. These wizards are not just for simplistic tasks, he said; they really get to the meat of Web services development. "They have a UDDI wizard. They also have wizards for creating Web services from a WSDL file," he noted. The wizards provide developers with a flexible but easy path to Web services development, according to Hightower. ...

Saturday, October 11, 2003

Wireless Modem, StarBucks, WebLogic 7, Mastering BEA WebLogic

I just got a wireless modem from SprintPCS. It is nice. I can get 150K bandwidth for $60.00 a month from anywhere in the U.S. where SprintPCS works. (Which seems to be everywhere....)

I got tired of not being able to connect. A lot of my clients have their networks locked down so its hard for me to send and recieve email. This way, I can stay connected no matter where I am. Some hotels have high speed, and some of the actually work, but why pay $10.00 a night.

I figured out how to use an exploded EAR file with an exploded WAR file in BEA WebLogic 7. I found the information on google. The info was written by the author of Mastering BEA WebLogic. So I figured it was in his book as well. BTW I really dig Mastering BEA WebLogic.

I got use to using WebLogic 8.1 which automatically expands EAR and WARs and lets you hot deploy JSPs and such.

Well I am off to StarBucks to write an article about Custom Tags and drink some liquid motivation.

Tuesday, October 07, 2003

Yet Another Discovery with LookUpDispatch and the resouce bundles

We are noticing the LookUpDispatchAction reads all of the bundles not just the default.
However, when you invoke an LookUpDispatchAction the first time, it cannot find the bundle/key if it is not the default. The second time and forevermore, it works.... it just fails the first time.

This may be a bug.

Another resoruce bundle discovery

The default bundle is not the first bundle in the struts config file (I read this somewhere).
It is the last bundle without a key. We found this out the hard way!

Struts 1.0 overides 1.1 resource bundle

I was helping a co-worker solve a problem.
Appraently if you have the application init parameter set for ActionServlet (which specifies the resoruce bundle), it overrides the one that is set in struts-config with message-resoruces.

The moral of this story, don't use the 1.0 init parameters with a 1.1 application.

Thursday, September 11, 2003

fun at Venice Beach

I am in LA visiting a client. They had a company picnic yesterday so I had the day off. I went to Venice beach for a few hours. Venice beach is very nice. It was bitter-sweet.

It gave me a chance to evaluate goals and priorities and sort of meditate while listening to the ocean. I love the ocean. I love the sound and the smell.

As I traveled west of Venice Blvd. I ....

Friday, September 05, 2003

How to ask a question?

I have written a couple of books and from time to time I get asked questions.
Most times these questions are pretty vague.

Jame Peterson knows how to ask a question.

He wrote me a little document that walks me through his environment. Pretty cool.

BTW I was still not able to really answer his question. It works on my box not on his.

Response

But at least I was able to try.

Wednesday, September 03, 2003

Tuesday, September 02, 2003

Will program Swing for remodeling.... (one day of my labor day)

I had a relative help me with some remodeling... Putting up some cabinets, hanging curtains and such. In exchange I helped his wife with a little problem at work.

I took some Excel spreadsheets that they used to track some billing data. I converted the highly unnormalized data from the Excel spreadsheet to a normalized set of database tables. I had to write a script in Python that would clean up the redundant data and arrange it into normalized tables (this was the longest part). I have to admit; I love this type of programming.

I then wrote a simple GUI to track items to bill. You enter in the serial number of the item, it shows its picture plus a list of maintenance parts. You just pick the part and the qty and hit add. Simple, but fun to write. I wrote it all in Swing.

It took me one day to write the data normalizer and the GUI.

You can add an optional date field (it defaults to today). I used the InputVerifier so you can't leave the date field until you enter in a proper date. I use labels associated with components that have displayMnemonics to make navigation easy.

90% of the GUI is written in HTML (I know I said swing, but swing does HTML). I use an EditorPane with its content type set to text/html. This allows me to easily put up pretty pictures of the machines (the machine changes based on the serial number), the company logo, the vendor logo, etc. I wrote the whole thing in Jython (Python running in the JVM).

I have a text field to enter in the serial number.... as you enter in the serial number, it highlights the closest serial number in a list, once you get close entering in the 10 digit serial number, you can pick it from the list. Then it pulls up that product data in a editable view (with a picture of the machine and a list of parts you can change).

I have to admit programming in Swing was fun, and a nice break from programming in Struts.

I am a big fan of Jython. I guess that is why I wrote a book on it. (Based on the book sales, there aren't as many jython fans as I would like.)

Thursday, August 28, 2003

Looking for something else and I ran into this....

Mastering Tomcat...

Picked up that one yesterday. I bought it cause Rick Hightower (Java Tools for Extreme Programming) wrote the chapter on struts and ant/xdoclet. I haven't been able to go through the whole thing yet, but I need good reference info and insight into how the new Jasper2 engine handles caching of tag libs and some of the quirks that come up in JSP/Servlet development WRT insuring clean separation of data in the various scopes. I'm also very interested in seeing how struts and the JSTL should behave in the container.


I want a raise from Wiley.

Improve JSTL i18n support with Struts

I’d like to see Struts play nice with JSTL i18n support.

I have a suggestion along these lines. (This is prelim. I am going to write some tests and do some prototyping but before I do… I’d like to hear if there are any thoughts on this).

Currently when you call Action.setLocale you get this:



...class Action...
    protected void setLocale(HttpServletRequest request, Locale locale) {
 
        HttpSession session = request.getSession();
        if (locale == null) {
            locale = Locale.getDefault();
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);
 
    }

I am suggesting this (for the release that embraces JSTL…. Struts 1.3 or 1.5).



import javax.servlet.jsp.jstl.core.Config; //get this guy to use its Locale key as well ...class Action...
    protected void setLocale(HttpServletRequest request, Locale locale) {
 
        HttpSession session = request.getSession();
        if (locale == null) {
            locale = Locale.getDefault();//Don’t agree with this, but that is a different story…
        }
        session.setAttribute(Globals.LOCALE_KEY, locale);
session.setAttribute(Config.FMT_LOCALE, locale); //See this…. See this…. See this…
    }


The Config.FMT_LOCALE is similar to the Globals.LOCALE_KEY except that it is for the JSTL tags, e.g.,



This is one possibility and the one that takes the least amount of effort. Another possibility is to change all struts i18n tags to use Config.FMT_LOCALE instead of Globals.LOCALE_KEY, which might be bad because it would break existing projects.

I am going to write a prototype along these lines in the near future. I need to test to see if fmt:message will work with Strut’s resource bundles. (I am not sure it they will or not... I think they will with a little arm twisting. I am still a little ignorant on the details... I got the big picture... just not all the details.). Any suggestions from you i18n gurus would be nice or if someone already started this... clue me in so I don't waste time.

This could be a first step in getting rid of our good friend bean:message and replacing him with fmt:message (or at least deprecating him a bit). :(

Don’t worry. I will add this to the Bugzilla feature request as soon as I test it.

APIs of the World Unite.... Fail Loud and Proud (Struts Action.setLocale)

From Nightly build....


protected void setLocale(HttpServletRequest request, Locale locale) {

HttpSession session = request.getSession();

if (locale == null) {
locale = Locale.getDefault();
}
session.setAttribute(Globals.LOCALE_KEY, locale);
}


Comments on setLocale from Action..

If the locale is null, wouldn't it be better for the default to come from the request as in request.getLocale(), which is the behavior of the tags when the Locale at Globals.LOCALE_KEY is not in session scope.

Better Yet.... Also if they call setLocale, shouldn't the local object be non-null. My personal opinion on this stuff is that it should explode with an illegal argument exception. (I remember a bug report that talked about Struts quietly handing illegal situations... this has been a long time complaint about Struts)

if (locale == null) {
throw new java.lang.IllegalArgumentException("Locale was null");
}


As a developer when I misuse an API, I like to see it fail quickly. This way I don't have to spend a lot of time debugging where I went wrong. Die early and often in development not during QA or. gulp.. Production!

Monday, August 25, 2003

Struts JSTL EL Validator rule

I told Erik about my new Validator rule, and he told me to try to contribute it. Erik is my open source mentor.

I tried to contribute it. I subscribed to the struts dev list, and posted the following:


I am new to this list so I apologize if I break any etiquette. I was thinking that I don't like validatewhen or requiredif so I wrote my own that uses JSTL EL. (I like the idea behind requiredif and validatewhen just not the implementation.) I believe this approach has several advantages over requiredif and validatewhen. I call this new rule validateel (I have not thought of a better name for it yet...).


Why write your own expression language? Why not use OGNL or JSTL EL? I think JSTL makes the most sense for the followig reasons:

1) EASY TO LEARN
The first advantage of this approach is it is easy to learn since developers know JSTL EL already. JSTL EL is easy to learn and you have to learn it for JSP 2.0 anyway. In fact, developers should be using JSTL tags in place of logic:* tags already.

2) ACCESS TO PAGE CONTEXT
The nice thing about this rule is that it has access to the complete pageContext (Headers, Request Parameters, Session, the whole thing) name space like any JSTL tag. (more on this trick later).

Since I am using JSTL EL I can make my expression as complex as need be, e.g., I can check to see if one date is before another or if a string starts with a certain substring. It is completely powerful, and yet very easy to learn and use.

3) VERY LITTLE CODE
This rule was very easy to implement. It relies on the Jakarta JSTL EL implementation. I don't see the point in adding a new expression language just for Struts when Struts relies on JSP and Servlets and JSP will be using JSTL. (Less code to add means less code to maintain....)

DETAILS:
...
(the rest you have seen in my blog)


This message was far more democratic and polite than my blog entry.

Thursday, August 21, 2003

What is requiredif and validatewhen.....??? (Struts validator)

I wrote about the JSTL validator that I created that I though was better than requiredif and validatewhen, and someone wrote me an email asking what requiredif and validatewhen were. (see my blog entry about the JSTL validator too)

They (requiredif and validatewhen) both account for...making fields required based on the value of other fields, or checking a relationship between fields.

So here goes....


Let's assume you want to make the state fields (as in a US state like a province in other countries) conditionally required only if the US checkbox field is set or the country drop down field is equal to the country code “us”. You would use the requiredif rule. The entry in your validation.xml file would look like this:


<form name="inputForm">

<field
property="state" depends="requiredif">
<arg0 key="inputForm.state "/>
<var>
<var-name>field[0]</var-name>
<var-value>us</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[0]</var-name>
<var-value>true</var-value>
</var>
<var>
<var-name>field[1]</var-name>
<var-value>country</var-value>
</var>
<var>
<var-name>fieldTest[1]</var-name>
<var-value>EQUAL</var-value>
</var>
<var>
<var-name>fieldValue[1]</var-name>
<var-value>us</var-value>
</var>
<var>
<var-name>fieldJoin</var-name>
<var-value>OR</var-value>
</var>
</field>


The field[n], fieldTest[n] and fieldValue[n] variables setup the expression. Thus the above states that in order for state to be required the us field has to equal “true” or country has to equal “us”. The fieldJoin variables joins the two expression. The fieldJoin value can be OR or AND, if AND then both of the expression have to be true. In addition to using EQUAL as a fieldTest, you can also use NULL and NOTNULL to see if the related properties are NULL or not.
The above is nice because it negates the need to override the ValidateForm’s validate method. However, it would not work for our password example earlier. For that more would be needed.
Requiredif might be deprecated in future releases
Future version of Struts passed version 1.1 may deprecate requiredif. The requiredif is considered very complex, especially when dealing with indexed fields (arrays of beans). The recommended way to perform this type of validation will be with the validwhen rule.

Beyond 1.1 conditional validation
As we showed earlier it is often the case that fields are validated based on the value of other fields. The example we did earlier in the chapter regarding password fields that are only valid if they are equal to each other. Thus we need to do more complex expressions than the requiredif rule provides. The validwhen validation rule is designed to handle these types of validation but it is not available until the release beyond 1.1. If you want in now, you will have to download the nightly source.
The validwhen rule takes a single test variable. The value of test must be a boolean expression. You can also refer to the current field under test with the keyword *this*. An example of using this with our password example is as follows:


<field property="password" depends="validwhen">
<arg0 key="inputForm.password"/>
<var>
<var-name>test</var-name>
<var-value>
((passwordCheck != null) and (*this* == passwordCheck))
</var-value>
</var>
</field>


The above would perform the same type of validation as the example we had earlier which required us to use override the validate method of the ValidateForm.
Here's a an example that redoes the requiredif example with validwhen as follows:



<field property="state" depends="validwhen">
<arg0 key="inputForm.state"/>
<var>
<var-name>test</var-name>
<var-value>
((us == "true") or (country == "us"))
</var-value>
</var>
</field>


You can also use validwhen with indexedProperties. Let’s say that the user registration form had two address, home address and shipping address. You would only want to validate the zip if address line one was set, you would use the following entry in the validation.xml file.


<field property="zip" indexedListProperty="addresses" depends="validwhen">
<arg0 key="inputForm.zip"/>
<var>
<var-name>test</var-name>
<var-value>((addresses [].addressLine1 == null) or (*this* != null))</var-value>
</var>
</field>

The address[] corresponds to the array of JavaBeans (e.g., ch15.Address). You are stating that the addresses[].zip is only required if the addresses[].addressLine1 is set.

Validator Rule that uses JSTL EL to validate multiple fields (and I hate coneys)

I was sitting at lunch eating a coney at Skyline in Cincinnati (not my favorite YUCK).... I from Tucson AZ, and I can't understand how Skylines draws such a crowd.

I was thinking how much I hate requiredif validator. I was also thinking that I don't like validatewhen much better.

Why write your own expression language? Why not use Ognl or JSTL?

I wrote my own version of validatewhen, and it uses JSTL lib from the Jakarta tag project. It took me about 20 minutes to write this. Short, sweet, and I'll never use validatewhen or requiredif again!

In my opinion, this new validate rule is much better than requiredif or validatewhen (at least the versions that I messed with). I can't believe someone did not think of tihs sooner.

It is also really easy to learn since you should know JSTL already.... Nothing special past that! (JSTL is easy and you have to learn it for JSP 2.0. You should be using JSTL tags in place of logic:* tags already.).

I call this new rule validateel (i have not thought of a better name for it yet... but I will, let me know if you think of one).

The nice thing about this rule is that it has access to the complete pageContext name space like any JSTL tag.
(more on this trick later).

Here is an example of using this rule to check to see if a passwordCheck field is equal to a password field as follows:


<field property="passwordCheck"
depends="validateel">
<arg0 key="inputForm.passwordCheck"/>
<var>
<var-name>test</var-name>
<var-value>
${value==form.password}
</var-value>
</var>



I created a FakePageContext class that takes a HttpServletRequest, and mocks up page context. I then add form to the fake page context as well as value inside of my new rule as follows:


PageContext pageContext = new FakePageContext(request);
String test = field.getVarValue("test"); //Get the test var (this is the JSTL expression)
pageContext.setAttribute("form",bean); //Map in the form
pageContext.setAttribute("field",field); //Map the field object (Just in case)
String value = ValidatorUtil.getValueAsString(bean, field.getProperty()); //Get the value of the property
pageContext.setAttribute("value",value); //Map the value into the page context.


The workhorse that actually does the JSTL expresion evaluation is from the JSTL lib. I just invoke it as follows:


result = (Boolean) ExpressionEvaluatorManager.evaluate("validateEL", test, Boolean.class, pageContext);



This was so easy... and IMHO it is better than requiredif and validatewhen. First... it uses JSTL which is an expression language people either know or should know (as it is required knowledge in JSP 2.0).

Here is the complete ValidateEL method and imports that implements this new validator rule.


import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.ValidatorUtil;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.Resources;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

/**
* @author rhightower
*
*/
public class CustomValidatorRules {

public static boolean validateEL(
Object bean,
ValidatorAction va,
Field field,
ActionErrors errors,
HttpServletRequest request) {

PageContext pageContext = new FakePageContext(request);
String test = field.getVarValue("test");
pageContext.setAttribute("form",bean);
pageContext.setAttribute("field",field);
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
pageContext.setAttribute("value",value);
Boolean result = Boolean.FALSE;
try{

result = (Boolean) ExpressionEvaluatorManager
.evaluate("validateEL",
test,
Boolean.class,
pageContext);

}catch (JspException je){
// TODO fix
je.printStackTrace();
}
boolean r = result.booleanValue();
if (r == false){
errors.add(
field.getKey(),
Resources.getActionError(request, va, field));

}

return r;

}
....


Here is the listing for the FakePageContext (it fakes the needed parts of the context and leaves the rest noops):



import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;

/**
* @author rhightower
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class FakePageContext extends PageContext {
HttpServletRequest request;
Hashtable map = new Hashtable();

public FakePageContext(HttpServletRequest request){
this.request = request;

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getAttribute(java.lang.String)
*/
public Object getAttribute(String key) {
return map.get(key);
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#setAttribute(java.lang.String, java.lang.Object)
*/
public void setAttribute(String key, Object value) {
map.put(key, value);

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#removeAttribute(java.lang.String)
*/
public void removeAttribute(String key) {
map.remove(key);

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getOut()
*/
public JspWriter getOut() {
return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getSession()
*/
public HttpSession getSession() {

return request.getSession(true);
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getPage()
*/
public Object getPage() {

return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getRequest()
*/
public ServletRequest getRequest() {

return this.request;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getResponse()
*/
public ServletResponse getResponse() {
// no op
return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getException()
*/
public Exception getException() {
// no op
return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getServletConfig()
*/
public ServletConfig getServletConfig() {

return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getServletContext()
*/
public ServletContext getServletContext() {

return null;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#forward(java.lang.String)
*/
public void forward(String arg0) throws ServletException, IOException {
//no op

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#include(java.lang.String)
*/
public void include(String arg0) throws ServletException, IOException {
//no op

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#initialize(javax.servlet.Servlet, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String, boolean, int, boolean)
*/
public void initialize(
Servlet arg0,
ServletRequest arg1,
ServletResponse arg2,
String arg3,
boolean arg4,
int arg5,
boolean arg6)
throws IOException, IllegalStateException, IllegalArgumentException {
//no op

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#setAttribute(java.lang.String, java.lang.Object, int)
*/
public void setAttribute(String key, Object value, int scope) {
if (scope ==PageContext.PAGE_SCOPE){
map.put(key, value);
}else if (scope == PageContext.REQUEST_SCOPE){
request.setAttribute(key,value);
}else if (scope==PageContext.SESSION_SCOPE){
request.getSession().setAttribute(key,value);
}else if (scope==PageContext.APPLICATION_SCOPE){
//TODO fix
}
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getAttribute(java.lang.String, int)
*/
public Object getAttribute(String key, int scope) {
if (scope ==PageContext.PAGE_SCOPE){
return map.get(key);
}else if (scope == PageContext.REQUEST_SCOPE){
return request.getAttribute(key);
}else if (scope==PageContext.SESSION_SCOPE){
return request.getSession().getAttribute(key);
}else if (scope==PageContext.APPLICATION_SCOPE){
return null; //TODO fix
}else {
return null;
}
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#removeAttribute(java.lang.String, int)
*/
public void removeAttribute(String key, int scope) {
if (scope ==PageContext.PAGE_SCOPE){
map.remove(key);
}else if (scope == PageContext.REQUEST_SCOPE){
request.removeAttribute(key);
}else if (scope==PageContext.SESSION_SCOPE){
request.getSession().removeAttribute(key);
}else if (scope==PageContext.APPLICATION_SCOPE){
//TODO fix
}else {
// no op
}

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getAttributeNamesInScope(int)
*/
public Enumeration getAttributeNamesInScope(int scope) {
if (scope ==PageContext.PAGE_SCOPE){
return map.keys();
}else if (scope == PageContext.REQUEST_SCOPE){
return request.getAttributeNames();
}else if (scope==PageContext.SESSION_SCOPE){
return request.getSession().getAttributeNames();
}else if (scope==PageContext.APPLICATION_SCOPE){
return null; //TODO fix
}else {
return null;
}

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#getAttributesScope(java.lang.String)
*/
public int getAttributesScope(String arg0) {
// No op
return 0;
}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#findAttribute(java.lang.String)
*/
public Object findAttribute(String key) {
Object value = map.get(key);
if (value == null){
value = request.getAttribute(key);
}
if (value == null){
value = request.getSession().getAttribute(key);
}
if (value == null){
//TODO look it up in app scope
}
return value;

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#handlePageException(java.lang.Exception)
*/
public void handlePageException(Exception arg0)
throws ServletException, IOException {
// No op

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#handlePageException(java.lang.Throwable)
*/
public void handlePageException(Throwable arg0)
throws ServletException, IOException {
// No op

}

/* (non-Javadoc)
* @see javax.servlet.jsp.PageContext#release()
*/
public void release() {
// No op

}

}


For completeness...

I had to add this entry in validation-rules.xml


<validator name="validateel"
classname="ch15.CustomValidatorRules"
method="validateEL"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
msg="errors.validateEL">
</validator>



It took me longer to write this blog entry then it did to write the above code. IMO if you are using requiredif or validatewhen, then you are wasting your time. Also, if you use the validator framework and you ever need to do a simple comparison of two fields... this is the way to go. With JSTL you have access to headers, attributes in session, request attributes, request parameters, and so much more.... Use this... it works and it is cool.

Here is how I would do the above in my own validate method of an ActionForm (for reference).


public class InputFormAll extends ValidatorForm {
...
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = super.validate(mapping, request);


if (!(password.equals(passwordCheck))){
errors.add(
"password",
new ActionError("errors.password.nomatch"));
}
return errors;
}



Using validateel is so much more terse! ${value==form.password} and I am done!