gamelan
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
KVM Switch over IP
Domain registration
KVM Switches
Laptop Batteries
Online Education
Compare Prices
Calling Cards
Disney World Tickets
Compare Prices
Imprinted Promotions
Computer Deals
GPS Devices
Corporate Awards
Imprinted Gifts

 


This report shows 5 trends that will emerge to allow Application Development and Program Management professionals to meet business expectations, include:

Diversification of software supply chain
Shorter development and delivery cycles
Disruptive technologies and architectures, and More.
Register now for your free Internet.com membership to download your complimentary Forrester report.
Limited Time Offer!
Membership will also give you access to:
eBook library         Whitepapers         Webcasts
Newsletters         WinDrivers
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Tip: Leveraging Struts2 Type Conversion
By David DeWolf

Type conversion is the process by which type-agnostic data is converted into more complex objects. These strategies are typically used in web applications to translate request parameters (strings) into the objects they represent. Although many web frameworks provide robust type conversion frameworks, many developers remain unaware of their powerful advantages and the simplicity with which they can be used.

Struts2 is one example of a web framework that provides a conversion approach that assists in translating request parameters into complex bean properties. By default, Struts2 will handle the conversion of parameters into primitives, collections (including indexed and mapped properties), and other simple objects (boxed types, dates, and arrays). Any time the framework identifies a request parameter that is mapped to a bean property of one of these types, it will utilize the default converter to translate the string value into the appropriate type. Developers often use these defaults without even realizing that they are part of a larger type conversion framework.

The real strength of the Struts2 Type Conversion Framework is the ability to add custom converters for use throughout the application. As an example, in the code snippet below, a type converter has been registered and will be used whenever a parameter name matches a bean property of type "com.threepillarsoftware.examples.PhoneNumber". The converter that is registered extends "org.apache.struts2.util.StrutsTypeConverter" and implements two methods—one for converting from a string, the other for converting to a string.



Click here for a larger image.

Figure 1: Registering the converter in xwork-conversion.properties entry.

The Struts2 framework will ensure that the PhoneNumber converter is invoked any time that a PhoneNumber is submitted. If a failure occurs during conversion, it will automatically handle the exceptions by adding error messages to the current action and triggering the appropriate result.



Click here for a larger image.

Figure 2: Converting from a String to a PhoneNumber

Figure 3: Converting from a PhoneNumber to a String

One of the advantages Spring provides over other web frameworks is its ability to load framework components, including type converters, through an externally configured bean factory. By using the struts2-spring-plugin in conjunction with type conversion, developers easily can use dependency injection to provide a converter with services. These services can be used to materialize objects from persistence, or provide adapters to other conversion strategies.

Developers often spend a lot of time manually handling conversions on a request-by-request basis. By leveraging type conversion features in Struts2 and other frameworks that provide them, developers can significantly reduce the amount of boiler plate code they need to write.

About the Author

David DeWolf is the chief technical architect and founder of Three Pillar Software, Inc. He works with mid-sized and Fortune 1000 companies to establish corporate standards that promote best practices and agile development. David has over eight years of commercial software development experience and is a member of the Apache Software Foundation's Struts, Tiles, and Portals projects. David actively participates in the Java Community Process as a member of the Java Portlet Specification Expert Group and is the author of various online publications.


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Java Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Five Trends for Application Development. Download Your Complimentary Report. Exclusive. Act Now.
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Intel Go Parallel Portal: Translating Multicore Power into Application Performance
Data Sheet: IBM Information Server Blade



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES