Child pages
  • StrutsBenefits
Skip to end of metadata
Go to start of metadata

List some benefits that Struts provides that you don't commonly see in other MVC architectures:

  • Widespread adoption and support. Struts has become the de facto MVC framework for J2EE projects.
  • Use of an easily configurable and maintainable application XML file that handles the flow of your application (and provides other functions). For example, imagine your application involves a JSP page that needs to gather employee information and insert this into a database. The XML file will have as one of its mappings /insertEmployee. This mapping can then contain what Action class will be called, whether you want validation to take place, whether you want the action to catch any particular Exceptions, and possible forwarding directions.
  • Dynamic Form Beans created automatically. In the struts-config.xml mentioned above, you can simply define the parameters you want a bean to have and associate this bean with a mapping and when a form submits it will automatically populate this bean that you created in your xml file. Need to add or remove a few fields- just remove them in the XML file and the bean created dynamically will have your changes.
  • Declarative Exception Handling. No need to hard code Exceptions that can be thrown by your Model layer into your controller or Command objects. Define these Exceptions in the struts-config.xml file and also where you want to forward to when particular Exceptions are thrown. Custom error messages you want to display never need to be hard-coded in your JSP pages or in any of your classes.
  • Eliminate the coding of many helper classes. Various Jakarta Commons packages come with Struts that make it very easy to tackle annoying and mundane tasks. For example, say you have a bean created that has all String parameters representing the fields of your form that are populated when the user submits the page. At some point you may need to get these properties into a more business oriented object (Data Transfer Object or Value Object). You could go through the trouble of building a helper class to call all the get and set methods and do type conversions, or you could simply call BeanUtils.copyProperties( objectCopiedTo, objectToCopyFrom ) and all the conversions are done for you. Saves the annoying tedious work of having to build helper classes.
  • Validation. Struts makes it a piece of cake to validate forms. No longer do you need to have all that complex Javascript in you code either. All you do is declare which form fields to validate in a validation.xml file and the validation framework takes cares of the rest. The custom error messages you want to display back to the user are all configured in a properties file which you can alter at any time. The validation framework even lets you pass in regular expressions and comes with some already set up for you (ie- validation of zip codes, e-mail, credit card number, etc). Validation of Dates, numbers, max/min lengths, etc. is now very simple and is done all on the server side meaning that, even if javascript is disabled on the client side, validation still takes place. Of course the framework will even automatically create the necessary javascript validation for you on the fly if you want that enabled. Which means that the same declarations that control the server side validation also control the client side javascript validation. Need to create some complex validation that isn't handled by the default validator framework? - No problem, you can easily just create your own classes that the framework can use.
  • Action Classes. These are analogous in functionality to Command objects (if you are used to that pattern). The nice thing about Struts is a request processor and the main controller (ActionServlet) is already created for you. You just create a mapping in the config.xml file and tell that mapping what Action class it needs to call and you just worry about coding the execute method of your Action class. Various other subclasses of this basic Action class come with Struts that you can extend to do some other powerful things ( FowardAction, DispatchAction, LookupDispatchAction, etc.).
  • ApplicationResources. Create simple property files that are then declared in your struts-config.xml file and your entire application has easy access to these properties with the bean:message tag construct. Custom errors and other messages to display are also coded here. Eliminates the need to hard code titles, headers, form elements, validation error messages, Exception error messages, etc.
  • A flexible and powerful templating system (Tiles) that allows you to define page fragments, enclose them in page definitions, and reuse these fragments and definitions across multiple pages. Tiles can be dynamically inserted and modified, and each tile can have its own Controller, facilitating even more flexibility.
  • No labels