Archive for August, 2007

Freelance web design - phone ^(?(d{3}))?[-| ]?(d{3})[ | ]?(d{4})$ zip ^d{5}(-d{4})?$ This

Tuesday, August 21st, 2007

phone ^(?(d{3}))?[-| ]?(d{3})[ | ]?(d{4})$ zip ^d{5}(-d{4})?$ This fragment includes two constants, phoneand zip, although you can include as many as you need. These constants are available to the elements within the formset section. You can reuse them many times within the formset simply by referring to them by name. This is best illustrated with an example. Example 11-1 shows a simple validation.xml file. Example 11-1. A simple validation.xml file
phone ^(?(d{3}))?[-| ]?(d{3})[ | ]?(d{4})$

mask ${phone}
In Example 11-1, the phoneconstant that’s declared in the global section is used in the var element to help validate the phone property. The formset element can contain two child elements, constantand form. The constant element has the same format as the one in the global section. It can be present zero or more times. The formelement can be present one or more times within the formset element:
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Web hosting providers - They are listed here without descriptions because the

Monday, August 20th, 2007

They are listed here without descriptions because the names are similar enough to the ones from Table 11-1 to indicate their functionality. validateByte validateCreditCard validateDate validateDouble validateEmail validateFloat validateInteger validateLong validateMask validateMinLength validateMaxLength validateRange validateRequired validateShort The StrutsValidator class contains the concrete validation logic used by Struts. This class and the methods listed above are declaratively configured in the validation-rules.xml file. When one of these methods is invoked and the validation fails, an ActionError is automatically created and added to the ActionErrors object. These errors are stored in the request and made available to the view components. 11.2.2.2 The validation.xml file The second configuration file that is required by the Validator framework is the validation.xml file. This file is application-specific; it describes which validation rules from the validation-rules.xml file are used by a particular ActionForm. This is what is meant by declaratively configured you don’t have to put code inside of the ActionForm class. The validation logic is associated with one or more ActionForm classes through this external file. The validation.xml file is governed by the validation_1_1.dtd. The outermost element is the form- validation element, which can contain two child elements, globaland formset. The global element can be present zero or more times, while the formset element can be present one or more times: The global element allows you to configure constantelements that can be used throughout the rest of the file: This is analogous to how you might define a constant in a Java file and then use it throughout the class. The following fragment shows a global fragment that defines two constants:
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Web site design and hosting - Before the minLength validation rule is called, the

Sunday, August 19th, 2007

Before the minLength validation rule is called, the required rule will be invoked. You can also set up a rule to depend on multiple rules by separating the rules in the depends attribute with a comma: depends=”required,integer” If a rule that is specified in the depends attribute fails validation, the next rule will not be called. For example, in the minLength validation rule shown previously, the validateMinLength( )method will not be invoked if the required validation rule fails. This should stand to reason, because there’s no sense in checking the length of a value if no value is present. The final attribute supported by the validator element is the jsFunctionName attribute. This optional attribute allows you to specify the name of the JavaScript function. By default, the Validator action name is used. The Validator framework is fairly generic. It contains very basic, atomic rules that can be used by any application. As you’ll see later in this chapter, it’s this generic quality that allows it to be used with non-Struts applications as well. The org.apache.commons.Validator.GenericValidator class implements the generic rules as a set of public static methods. Table 11-1 lists the set of validation rules available in the GenericValidatorclass. Table 11-1. Validation rules in the GenericValidator class Method name Description isBlankOrNullChecks if the field isn’t null and the length of the field is greater than zero, not including whitespace. isByte Checks if the value can safely be converted to a byte primitive. isCreditCard Checks if the field is a valid credit card number. isDate Checks if the field is a valid date. isDouble Checks if the value can safely be converted to a double primitive. isEmail Checks if the field is a valid email address. isFloat Checks if the value can safely be converted to a float primitive. isInRange Checks if the value is within a minimum and maximum range. isInt Checks if the value can safely be converted to an int primitive. isLong Checks if the value can safely be converted to a long primitive. isShort Checks if the value can safely be converted to a short primitive. matchRegexp Checks if the value matches the regular expression. maxLength Checks if the value’s length is less than or equal to the maximum. minLength Checks if the value’s length is greater than or equal to the minimum. Because the validation rules in the GenericValidator are so fine-grained, the Struts developers added a utility class to the Struts framework called org.apache.struts.util.StrutsValidator , which defines a set of higher-level methods that are coupled to the Struts framework but make it easier to use the Validator with Struts.
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Web design tools - The nameattribute assigns a logical name to the

Saturday, August 18th, 2007

The nameattribute assigns a logical name to the validation rule. It is used to reference the rule from other rules within this file and from the application-specific validation file discussed in the next section. The name must be unique. The classnameand method attributes define the class and method that contain the logic for the validation rule. For example, as shown in the earlier code fragment, the validateRequired( ) method in the StrutsValidator class will be invoked for the required validation rule. The methodParams attribute is a comma-delimited list of parameters for the method defined in the method attribute. The msgattribute is a key from the resource bundle. The Validator framework uses this value to look up a message from the Struts resource bundle when a validation error occurs. By default, the Validator framework uses the following values: errors.required={0} is required. errors.minlength={0} cannot be less than {1} characters. errors.maxlength={0} cannot be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be a byte. errors.short={0} must be a short. errors.integer={0} must be an integer. errors.long={0} must be a long. errors.float={0} must be a float. errors.double={0} must be a double. errors.date={0} is not a date. errors.range={0} is not in the range {1} through {2}. errors.creditcard={0} is not a valid credit card number. errors.email={0} is an invalid email address You should add these to your application’s resource bundle, or change the key values in the validation- rules.xml file if you plan to use alternate messages. The depends attribute is used to specify other validation rules that should be called before the rule specifying it. The depends attribute is illustrated in the minLengthvalidation rule here:
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Web server hosting - 11.2.2.1 The validation-rules.xml file The validation-rules.xml configuration file

Friday, August 17th, 2007

11.2.2.1 The validation-rules.xml file The validation-rules.xml configuration file contains a global set of validation rules that can be used out of the box by your application. This file is application-neutral and can be used by any Struts application. You should need to modify this file only if you plan to modify or extend the default set of rules. If you do need to extend the default rules, you might be better off putting your custom rules in a different XML file, so as to keep them separate from the default ones. This will help when it comes time to upgrade to a newer version of the Validator framework. The validator-rules_1_1.dtd describes the syntax of the validation-rules.xml file. The root element is the form-validation element, which requires one or more global elements: Each validator element describes one unique validation rule. The following fragment from the validation-rules.xml file is the definition for the required validation rule: The validatorelement also allows a subelement, but for the sake of brevity it is not shown here. The JavaScript support in the Validator framework is discussed later in the chapter. The validator element supports seven attributes, as shown here:
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

The first problem is that (Web hosting company) coding validation logic

Friday, August 17th, 2007

The first problem is that coding validation logic within each ActionForm places redundant validation logic throughout your application. Within a single web application, the type of validation that needs to occur across HTML forms is very similar. The need to validate required fields, dates, times, and numbers, for example, typically occurs in many places throughout an application. Most nontrivial applications have multiple HTML forms that accept user input that must be validated. Even if you use a single ActionForm for your entire application, you might still end up duplicating the validation logic for the various properties. The second major problem is one of maintenance. If you need to modify or enhance the validation that occurs for an ActionForm, the source code must be recompiled. This makes it very difficult to configure an application. The Validator framework allows you to move all the validation logic completely outside of the ActionForm and declaratively configure it for an application through external XML files. No validation logic is necessary in the ActionForm, which makes your application easier to develop and maintain. The other great benefit of the Validator is that it’s very extensible. It provides many standard validation routines out of the box, but if you require additional validation rules, the framework is easy to extend and provides the ability to plug in your own rules (again without needing to modify your application). 11.2 Installing and Configuring the Validator The Validator framework is now part of the Jakarta Commons project. It’s included with the Struts main distribution, but you can also get the latest version from the Commons download page at http://jakarta.apache.org/commons/. Unless you need the source code or the absolute latest version, you’ll find all the necessary files included with the Struts 1.1 distribution. 11.2.1 Required Packages The Validator depends on several other packages to function properly, and the most important of these is the Jakarta ORO package. The ORO package contains functionality for regular expressions, performing substitutions, and text splitting, among other utilities. The libraries were originally developed by ORO, Inc. and donated to the Apache Software Foundation. Earlier versions of the Validator framework depended on a different regular expression package, called Regexp, which is also a Jakarta project. However, ORO was considered the more complete of the two, and the Validator that is included with Struts 1.1 now depends on the ORO package. Other packages required by the Validator are Commons BeansUtils, Commons Logging, Commons Collections, and Digester. All of the dependent packages for the Validator are included in the Struts 1.1 download. The commons-validator.jar and jakarta-oro.jar files need to be placed into the WEBINF/lib directory for your web application. The other dependent JAR files must also be present, but they should already be there due to Struts framework requirements. 11.2.2 Configuring the Validation Rules As mentioned earlier, the Validator framework allows the validation rules for an application to be declaratively configured. This means that they are specified externally to the application source. There are two important configuration files for the Validator framework: validation- rules.xmlandvalidation.xml.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

interface, there’s no guarantee that the (Domain and web hosting) container will

Thursday, August 16th, 2007

interface, there’s no guarantee that the container will provide the tag with an opportunity to release the resources being used by the tags. 10.5.3 Internationalized Exception Handling Chapter 12 covers internationalization in detail, but it’s relevant to say a few words here about how exception handling and internationalization are connected. While throwing exceptions in Java, developers often do something like the following: // Detect some problem and throw an exceptionthrow new InvalidLoginException( “An exception hasoccurred.” ); The problem with hardcoding the string into the exception is that it’s useful only for developers from the same locale. It might be difficult for developers or system administrators from different locales to use the log files where these exceptions are logged. Instead of hardcoding the messages for the exceptions, it may be better to get the message from a resource bundle. Obviously, exceptions that are thrown from third-party packages are not within your control, just as stack traces are hard to localize. Many organizations don’t worry about localizing the exception messages, which is fine as long as no one from locales other than your own will ever need to use the information. 10.6 Conclusion The new declarative exception handling is a great addition to the Struts framework and one that should certainly save developers time, during both initial development and maintenance. Whenever possible, you should make a serious effort to take advantage of the declarative exception-handling features rather than attempting to write your own. The good news remains, however, that if you do need to create your own customized exception handling, the freedom and flexibility for you to do so exists in the framework. Chapter 11. The Validator Framework The Struts framework allows input validation to occur inside the ActionForm. To perform validation on data passed to a Struts application, developers must code special validation logic inside each ActionForm class. Although this approach works, it has some serious limitations. This chapter introduces David Winterfeldt’s Validator framework, which was created specifically to work with the Struts components and to help overcome some of these limitations. The Validator allows you to declaratively configure validation routines for a Struts application without programming special validation logic. The Validator has become so popular and widely used by Struts developers that it has been added to the list of Jakarta projects and to the main Struts distribution. 11.1 The Need for a Validation Framework Chapter 7 discussed how to provide validation logic inside the ActionForm class. The solution presented there requires you to write a separate piece of validation logic for each property that you need to validate. If an error is detected, you have to manually create an ActionError object and add it to the ActionErrors collection. Although this solution works, there are a few problems with the approach.
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

Often, the application will not be able to (Web server info)

Wednesday, August 15th, 2007

Often, the application will not be able to recover from a RemoteException and will have to display the system error page. If you’re using EJB and you get a RemoteException, you can attempt to recover by acquiring a new remote reference, but there’s probably some type of programming or environment error that will prevent the end user from continuing. Whether you’re using a programmatic or a declarative approach, you’ll likely want to log the exception, create and store an ActionError object, and then forward to the system error page. You can also define the exception-handling behavior to forward the user back to the previous page and give her the choice of trying again. If some type of network blip caused the remote exception, it may be possible for the user to continue to use the application. 10.5.2 Exceptions in Custom Tags JSP custom tags usually throw JSPException objects or one of their descendants. Prior to the JavaServer Pages 1.2 specification, the JSPException class didn’t support exception chaining, and because Struts was introduced before the 1.2 specification, several places inside the Struts custom tag libraries still disregard the original exception when a JSPException is created. However, the Struts tags do usually store the exception in the request scope under the key Action.EXCEPTION_KEY, which maps to a literal string of org.apache.struts.action.Action.EXCEPTION_KEY. If you need to get access to the root cause, you can probably use this key to retrieve the exception object. Version 1.2 of the JSP specification modified the JSPException to support exception chaining; however, the Struts developers will probably choose to leave the current tags alone for backward compatibility and will take advantage of this new functionality only for future tags. However, in the custom tags that you create, you should use the rootCausefield in the JSPException class when you rethrow exceptions as different types. 10.5.2.1 The TryCatchFinally interface The JSP 1.2 specification also introduced a new interface called TryCatchFinally. This interface, which is referred to as a “mix-in” interface, can be implemented by a tag handler in addition to one of the other tag interfaces. The TryCatchFinally interface provides two methods: public void doCatch(Throwable); public void doFinally( ); The container calls the doCatch( )method if the tag body or one of the doStartEnd( ), doEndTag( ), doInitBody( ), or doAfterBody( )methods throws a Throwable. The doCatch( )method can rethrow the same or a different exception after handling the error. The container calls the doFinally( )method after the doEndTag( ) or after the doCatch( )method when an exception condition occurs. The TryCatchFinally interface allows for better exception handling in custom tags. It is very important to allow limited resources that are being used by custom tags to be released. Without this
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

* user locale. For (Web server info) example, if there is

Tuesday, August 14th, 2007

* user locale. For example, if there is a Date object inthe array, it * would need to be formatted for each locale. */ // Now construct an instance of the ActionError class if ( args != null && args.length > 0 ){ // Use the arguments that were provided in the exception newActionError = new ActionError( errorCode, args ); }else{ newActionError = new ActionError( errorCode ); } errors.add( ActionErrors.GLOBAL_ERROR, newActionError ); } The processBaseException( )method is responsible for creating the ActionError object. It uses the messageKey field to look up a bundle message, and if any arguments are included, it includes those in the ActionError constructor as well. As you can see, adding programmatic exception handling to your applications definitely requires more work than using the default behavior provided by the Struts framework. It also makes maintenance more difficult if you drastically change your exception hierarchy or change how you want to handle certain exceptions. However, if you are using an earlier version of Struts, this may be your only choice. You may have to extend these examples for your own applications, but they show a well-designed approach that you can build upon. Within the EJB and Servlet specifications, programmatic security is frowned upon because it’s too easy to couple your application to the physical security environment. With exception handling, it’s unlikely that you’ll need to change the exceptions that are thrown based on the target environment. Therefore, there isn’t the same stigma associated with programmatic exception handling as there is with programmatic security. It is true, though, that if you can take advantage of declarative exception handling, your application will be easier to maintain than if you have the same functionality in your source code. An application will almost always be modified over time, and new exceptions will need to be thrown and caught. The more you can specify declaratively, the easier time you’ll have maintaining it. 10.5 Tying Up the Loose Ends Before we leave the topic of exception handling, there are several special cases that we should discuss. Each one of these is unique, and you may or may not need them in your applications. 10.5.1 Handling Remote Exceptions Remote Java objects are allowed to throw instances of java.rmi.RemoteException. In fact, every EJB method that is exposed to a remote client must declare that it throws RemoteException. Dealing with RemoteExceptions is very similar to handling system exceptions except that they are not descendants of either java.lang.Erroror java.lang.RuntimeException.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

} } // Tell the Struts framework to (Web site designers)

Monday, August 13th, 2007

} } // Tell the Struts framework to save the errors into therequestsaveErrors( request, errors ); // Return the ActionForwardreturn forward; } The processExceptions( )method seems quite complex, but it’s really not that bad. Here are the steps that the method performs: 1. Obtain the locale for the user. 2. Call the processBaseException( )method to process the top-level exception. 3. If there are any subexceptions, process each one. 4. Save all of the ActionErrors that were created. 5. Return control back to either the resource identified in the input attribute of the action or a “Failure” ActionForward that has been configured for the action. The processBaseException( )method is where the ActionError objects are created. This method is shown in Example 10-9. Example 10-9. The processBaseException( ) method of the StorefrontBaseAction class protected void processBaseException( ActionErrors errors, BaseException ex, Locale locale) { // Holds the reference to the ActionError to be added ActionError newActionError = null; // The errorCode is the key to the resource bundle String errorCode = ex.getMessageKey( ); /** * If there are extra arguments to be used by theMessageFormat object, * insert them into the argList. The arguments are contextsensitive * arguments for the exception; there may be 0 or more. */ Object[] args = ex.getMessageArgs( ); /** * In an application that had to support I18N, you mightwant to * format each value in the argument array based on itstype and the
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.