Search WebSpherePower's 6,545 WebSphere, Java, and Eclipse article archive 
Home
EasyPrint
News details Click here for the RSS feed's XML code. This is not a browser URL.
Articles-only Click here for the RSS feed's XML code. This is not a browser URL.
Twitter Feed Click here for the Twitter feed.
Using a reusable code approach to HTML select option lists, part V (continued)

This is a very simple module, but in order for it to work, it needs two pieces of information:

  • the name of the OptionListSourceFactory that we will be using to produce our OptionListSource object;

  • The name of the OptionListSource object that we need to pass to the factory in order to obtain the source that is applicable to the field being validated.

If you have been following along in this series, you may wonder why we need to pass the name of the factory to the validator since we only created one factory and made no provisions for a collection of factory variations. While that is true, that is just the nature of the shortcut we took to introduce the factory concept. For a complete, production-grade implementation of the factory concept, you should have a factory interface just as we have an OptionListSource interface, and factories should be produced based on a common set of base code contained in an abstract class. Since we elected not to do that, we don't really need to pass the class name of the factory to our validator, but I included that step in here, just because that's really the way it ought to be done.

Once our validator has obtained the option list from the OptionListSource (which it obtained from the factory using the name parameter provided) all that is left for it to do is to iterate through the list of valid values and determine if the user input is on the list. If not, it simply notifies the Struts validation framework and lets the built-in validation features of that framework take care of the rest of the work. All in all, it works out pretty slick thanks to most of the work already being provided by Struts.

Configuring the validator
To make this all work, there are still two more things to do:

  • Define the validator in the Struts validator-rules.xml file;

  • Set up any field validations that you want to have use our new validator.

The entry in the validator-rules.xml is presented here:


<validator name="validValues"
classname="step.five.ValidValuesValidator"
method="validateValidValues"
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.valid.values">

<javascript><![CDATA[
function validateValidValues(form) {
return true;
}

]]>
</javascript>

</validator>

Next up is a sample of what a field validation entry in the validation.xml file would look like:


<field property="priority"
depends="required,validValues">
<arg0 key="label.priority"/>
<var>
<var-name>factoryClass</var-name>
<var-value>step.five.OptionListSourceFactory</var-value>
</var>
<var>
<var-name>optionListName</var-name>
<var-value>priority</var-value>
</var>
</field>


« Previous  ·  1  ·  2  ·  3  ·  Next »
Other articles you might like
Home > Projects > Reusable Code (5 articles)
   Using a reusable code approach to HTML select option lists, part VI
   Using a reusable code approach to HTML select option lists, part IV
   Using a reusable code approach to HTML select option lists: part III
Get Weekly Email Updates
Subscribe to our regular weekly email newsletter. It's packed with tips, reviews, deep analysis, and the latest news.
 
Recent WebSpherePower Articles
A perfect 10: celebrating 10 years online
You can help bring security and safety back to White House email
Introducing the WebSpherePower RSS feeds
From New Jersey to Palm Bay, Florida
A WebSphere pot o' gold
How Elvis entered the building and CES went out the window
WebSphere Application Server 6: what's it all mean?
WebSpherePower News
eCube Systems Announces NXTera 6.0 Release
HTML & CSS: The Good Parts
Just How Fast Is Cisco's New Router?
10 Years After: A Look Back at the Dotcom Boom and Bust
LiveTime Extends ITSM SaaS Platform to Google App Engine and Amazon EC2 Cloud
Synology Releases DiskStation Manager 2.3
Debugging C++ applications using ProbeVue
>> Read all the news
More from the ZATZ journals
Computing Unplugged: Make Mafia Wars an offer it can't refuse
David Gewirtz Online: CNN commentary and analysis
DominoPower: Application development, William Shatner, and the origin of the universe
OutlookPower: Removing an Office installation that doesn't want to go away
-- Advertisement --

SECURE YOUR SITE WITH AN IRONCLAD SSL CERTIFICATE
An IronClad SSL Certificate helps you build an impenetrable fortress around your customer's credit card information. IronClad SSL Certificates are:

  • Fully validated
  • Up to 256-bit encryption
  • One, two, or three year validity (our Turbo SSL Certificates are valid up to 10 years)
  • 99% browser recognition
  • Stringent authentication
  • Around-the-clock customer support

Build trust. Protect your customers. Grow your online business.

Tap here now and be IronClad with SSL tonight.

-- Advertisement --

Influencer. Recommender. Decision Maker.
They all read WebSpherePower Magazine. They all rely on WebSpherePower Magazine.

If you want to reach the inner-circle of IBM IT professionals, you won't find a better resource than WebSpherePower Magazine.

Click for our Media Kit

ZATZ Home  ·  News  ·  Back Issues  ·  Credits/Trademarks ·  Link To Us
Copyright © 2010, ZATZ Publishing. All rights reserved worldwide.
Editor's Login