Professional Struts Applications: Building Web Sites with Struts, ObjectRelationalBridge, Lucene, and Velocity

ion is the key to avoiding a ripple effect. If the SQL logic for the application is cleanly hidden behind a set of interfaces that did not expose the actual structure of the database table to the application, the chance of a ripple effect occurring is much less. In the next chapter we will demonstrate how to use some basic design patterns to achieve this goal. The code shown above is difficult to follow and maintain. Even though the business logic for the Post A Story page is very simplistic, it still took almost two pages of code to implement. Keep the following in mind, while building your first Struts-based application: Development frameworks like Struts are used for building applications. However, the business logic in applications often belongs to the enterpri e and not ju t a single application. How many times have you een the bu ine logic cut across multiple applications within an organization? Be wary of embedding too much business logic directly within Struts. Otherwise you might find that reuse of business logic becomes extremely difficult. Tier Leakage and Struts Many development teams will get an uneasy feeling about the amount of business logic being placed in the Struts Action class. They might have already run into situations where they have the same business logic being reused in many of their applications. The natural tendency is to refactor the Struts code and move it into a component-based architecture (such as EnterpriseJavaBeans) or services-based architecture (such as web services). This moves the business logic out of the Struts Action class and makes it eaSily available to the other applications. Let's refactor the PostS tory class and move all of the business logic into an Enterprise JavaBean called StoryManager. The code for the rewritten PostStory class is shown below: package com.wrox.javaedge . struts . poststory; import org.apache . struts.action.*; import javax.servlet.http . *; import javax . naming.*; import javax.ejb.*; import java.rmi . *; import javax . rmi . *; import com.wrox.javaedge.common.*; import com.wrox.javaedge . story . *; import com .wrox . javaedge .member.*; import com.wrox.javaedge.story.ejb.*; public class PostStory extends Action public ActionForward perform{ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {