Struts Survival Guide 113
Struts Survival Guide: Basics to Best Practices | |
author | Srikanth Shenoy, Nithin Mallya |
pages | 224 |
publisher | ObjectSource Publications |
rating | 8 |
reviewer | Wilson Fereira |
ISBN | 0974848808 |
summary | A short but valuable guide to the Jakarta Struts framework. |
Even before I started reading the book, the fact that stood out most was its pricing. The book costs $14.95, and is great buy for everybody and especially students. The book is light -- just 224 pages -- and is an easy read. The authors' style is neither dry nor humorous, but very convincing and developer friendly. Bottom line: It does not put you to sleep.
There are two aspects to any framework: the first aspect is the features of the framework itself; the second aspect is how easy it is to use them effectively. This book does justice to both aspects of Struts. It covers enough framework features to justify its title, starting from bare bones and then slowly guiding you to more advanced topics. In addition, there are chapters dedicated to dealing with variety of scenarios in web applications where Struts can be used to solve the problems effectively. This is the area where the book shines.
Chapter-wise reviews
The book starts off with an excellent introduction to MVC and how Struts fits into MVC. It then explains the basics of Struts very well and develops a hands-on application in Struts in the first three chapters.The fun starts from Chapter 4 onwards. Chapter 4 covers advanced Struts concepts and presents some interesting ideas about Struts Action design. Of particular interest are the coverage of how to protect your JSPs from direct access, using SwitchAction to navigate between multiple Struts modules. The different mechanisms of Action chaining and scenarios where Action chaining is not recommended is also an enlightening read. One of the controversial points in the book is that author discourages you from using XDoclet and explains why XDoclet is not a great idea with Struts.
Chapter 5 covers the validation in Struts. It is the shortest write up on Validation I have ever read and yet it beautifully explains the Commons Validator and its integration with Struts. In the context of validation, the author also explains when to use DynaActionForm and its derivatives and when not to.
Chapter 6 deals with Struts Tags. Reading this chapter was such a refresher. Other books on Struts have bored me with details of each attribute of each tag in Struts. I find this approach non-intuitive since that information is supposed to be a cross-reference and available on Struts web site anyway. Not so with this book. This book takes the approach of explaining the basic tags by example. In chapter 6, the author dives straight into practical aspects of building web applications with Struts. One of the very first illustration is why and how to modify BaseTag (the one that renders ) to suit the real life deployment scenarios. Next the chapter takes up one of the serious issues with check boxes regarding their state and provides a solution. The chapter provides technique for seamlessly integrating JavaScript validations with Struts validation. A lot of Struts web application that we develop do not use plain buttons. Instead image buttons are used. Perhaps the author was very aware of this fact and the lack of support for image based form submissions in Struts. That is why the chapter and the book has frequent references and solutions for dealing with Image buttons. It all starts in this chapter with a great introduction and some classes that make the form submission on the JSP transparent to the Action classes.
The Chapter 6 provides little details on the Struts Bean tag library except for dealing with multiple resource bundles and some design tips. Perhaps the reason is that the bean tags are so straight forward and covered well in the Struts web site. Another highlight of the chapter is a short yet great coverage of JSTL as a background for Struts-EL. The JSTL is introduced in the context of Struts Logic tags as a solution to deal with convoluted and and confusing nested tags. The section on Struts-EL is really short and could have been more.
The creme la creme of Chapter 6 is the section on dealing with List Forms. Sometimes you often have to deal with Forms with collection, edit the collection or delete the collection. Developers are confused on this topic as is evident from the postings in Struts mailing lists. The author does a great job of resolving the mystery surrounding editable collections in Forms. The author also does a great job of integrating the Pager Taglib from JSPTags.com with Struts and how a high performance page traversal mechanism can be set up based on the ValueListIterator pattern (Core J2EE Pattern) and database specific mechanisms.
Chapter 7 is a very decent way to learn Tiles. Tiles can be very confusing due to its capability to achieve the same thing in numerous ways. The author sticks to just one approach of using Tiles with Struts and defends why that is the best approach. The pros of this approach are there are confusions and the learning curve with Tiles is flattened. Coverage of Tiles Controller is missing and is desirable.
Chapter 9 on Exception handling in Struts deserves some mention. It is one of the best exception handling chapters I have ever read. Most other books on Struts limit their exception chapter to explaining differences between Checked v/s Unchecked exceptions and telling how the tags work in the struts-config.xml. The coverage of Exception handling in this book alone is worth the price of the book. It provides a solid framework to handle Exceptions in Struts, log them in a centralized manner and report and alert in a production environment.
Chapter 10 is for folks who want to customize Struts and reap its benefits in design and development of production systems. It presents four examples of how Struts can be effectively customized. The best among them was how to how to handle duplicate form submissions in a generic manner. We all have to deal with duplicate form submissions in daily life and handle them on use case basis by using the Synchronizer tokens. The technique illustrated here no doubt relies on the Sync token but uses it a very ingenious manner, presents a generic Action class. I liked this technique. Other techniques I liked are that the chapter provides a Dispatch Action like functionality for Image based form submission. The DispatchAction in Struts is great, unfortunately I can use it only under certain restrictions. One of them is that the all of the buttons have to have the same name. This technique removes that restriction and opens a world of possibilities for designing cleaner applications while providing enhanced user experience.
If there is a feature in Struts which is not the best way to attack a problem, this book tells you that. The chapters are also interspersed with design tips for designing your Struts application better. In summary, this is a pragmatic Struts book and a highly recommended read for developers and architects already familiar with Struts. You will certainly pick up quite a bit of Struts tricks that will help you design better Struts applications. If you architect, design and develop Struts based applications for your living, do yourself a favor - Go buy this book. Even if you don't know Struts, you can learn it fast with this book. The only requirement is that you should already know the basics of how to develop J2EE web applications.
You can purchase Struts Survival Guide: Basics to Best Practices from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
better survival guide (Score:3, Informative)
Re:No please... (Score:5, Informative)
Compared to what? Pure JSP? Maybe if you have like two pages total, but if you have any more than that you'll discover that:
If you set out to solve these problems, you'll inevitably end up at struts. It may do other things (don't know; I haven't ventured in that deeply), but it does these in about as simple a way as anyone could.
I challenge you to find any significant amount of redundant code in a project of mine that uses struts: mb. Description here [slamb.org], browse the code here [slamb.org]. There's not a lot of code there, and struts is largely responsible.
Internally, struts may be hugely overengineered...but I, as a user, don't care. It helps me keep my applications more terse and well-organized. (Much more maintainable than what I wrote before.)
Check out spring... (Score:5, Informative)
A framework I am working with currently is spring [springframework.org].
Spring is a superb framework for Java development and includes a pretty impressive MVC web toolkit as well as many other tools and features. The AOP stuff is very nice and the whole inversion of control/dependancy injection implementation simplifies code drastically.
Ive used quite a few different frameworks, but so far... this one is my favourite.
just say no to struts (Score:2, Informative)
Struts rocks! (Score:1, Informative)
Re:Check out spring... (Score:4, Informative)
I've tried using Struts a few times, but it kept failing my 30 minute rule. (30 minutes to at least get some demo going other than "Hello World") Whereas I had the same idea of a demo going in Spring in about 15 minutes, on the first try.
I think Spring's advantage is it's IoC style of configuration and it's use of POJOs instead of the Struts style of extending one of their classes for everything.
Struts & WebObjects? (Score:4, Informative)
Fundamentally, Struts is a refactoring of the basic servlet API, but is still intrinsically operation-based (as are pure servlets).
WebObjects, and it's thematic successor Tapestry [apache.org] are component based approaches, an entirely different mindset. I created Tapestry and I have about two years of Struts experience ... Struts is a straight-jacket. Component frameworks offer incredible advantages in terms of clarity and developer productivity. Struts offers very, very little except a slew of books that have the daunting task of explaining in detail something that should be (was intended to be) very simple.
Struts is great but.... (Score:5, Informative)
http://java.sun.com/j2ee/javaserverfaces/
This is the framework that is being adopted by all major java IDE designers: NetBeans, Borland, Oracle etc. Fortunately, its not difficult to integrate struts and JSF, but for newer projects, JSF makes sense. It has an advantage in that the GUI doesn't have to be web pages - you will be able to 'plug in' WAP, Swing etc.
Re:No please... (Score:1, Informative)
There's lots of MVC jibba jabba from Struts foo's, but you don't need Struts for MVC, and using Struts means you have to put up with its many questionable design choices:
1. Singleton Actions.
I've read that this was due to performance, but that seems rather silly. If instantiating a form bean and populating it via reflection is acceptable, why is creating an instance of an Action a problem?
2. Decoupling Actions and Form beans.
Frankly, the seperation of Action (behavior) and Form (data) seems anti-OO. Doesn't anyone else cringe when they see the following standard struts idiom?
public ActionForward doStuff(ActionMapping m, ActionForm form,
MyFormType myForm = (MyFormType) myForm;
}
3. Reflective population of form beans, no mechanism for describing how to create a form in a valid state.
Bad idea. No compile-time checking, nothing resembling pre-condition declarations, and consequently code that is very sloppy and difficult to test (how many possible states does a form bean have?). Also, potentially insecure, particularly when a Form bean is used for only some of its attributes by an Action. What happens if someone builds a "hostile" http request?
4. XML config.
I could never understand this. What's the value of defining the action forwards and dyna action forms in another language (ie the config XML) that is not programmatically accessible from the Java code? Its not like you can change struts config without changing the corresponding Java.
Re:Struts is great but.... (Score:5, Informative)
Re:Struts is great but.... (Score:3, Informative)
This is completely wrong. JSF is a total replacement for struts at all levels: model, view and controller. The JSP aspect of JSF is only one implementation of the presentation layer of JSF, and the reference implementation of JSF includes a JSP taglib front-end. One of the big advances of JSF is that it can in principle render all sorts of interfaces: WAP, XML, Swing, SWT, yet the underlying Java code and XML mapping of actions and validators remains the same. JSF is designed to be more than just a web form coding system.
Struts will allow you to use Java Server Faces JSP tags for the view, but that is only one small part of JSF.