Archive for August, 2007

import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.Field; import org.apache.commons.validator.GenericTypeValidator; import org.apache.commons.validator.GenericValidator; (Web hosting service)

Friday, August 31st, 2007

import javax.servlet.http.HttpServletRequest; import org.apache.commons.validator.Field; import org.apache.commons.validator.GenericTypeValidator; import org.apache.commons.validator.GenericValidator; import org.apache.commons.validator.ValidatorAction; import org.apache.commons.validator.ValidatorUtil; import org.apache.struts.action.ActionErrors; import org.apache.struts.util.StrutsValidatorUtil; public class NewValidator implements Serializable { /** * A validate routine that ensures the value is either true or false. */ public static boolean validateBoolean( Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequestrequest ) { String value = null; // The boolean value is stored as a String if (field.getProperty() != null && field.getProperty().length( ) > 0){ value = ValidatorUtil.getValueAsString(bean, field.getProperty( ) ); } Boolean result = Boolean.valueOf(value); if ( result == null ){ errors.add( field.getKey( ), StrutsValidatorUtil.getActionError(request, va, field)); } // Return true if the value was successfully converted, false otherwise return (errors.empty( )); } } The next step is to add this new rule to the validation-rules.xml file, or to a new file to keep your customized rules separate. The validator element for the validateBooleanrule should look something like: Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

11.4 Creating Your Own Validation Rules (Web hosting ecommerce) The Validator

Thursday, August 30th, 2007

11.4 Creating Your Own Validation Rules The Validator framework is preconfigured with many of the most common rules that you’re likely to need for your Struts applications. If your application has validation requirements that are not met by the default rules, you have complete freedom to create your own. There are several steps that you must follow, however, to create your own customized rules: 1. Create a Java class that contains the validation methods. 2. Edit the validation-rules.xml file or create your own version. If you do create a new validation resource file, be sure to add it to the list of resource files in the Validator plug-in. 3. Use the new validation rules in the validation.xml file for your application. Each validation method you create must have the following signature: public static boolean validateXXX( java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest, javax.servlet.ServletContext ); where validateXXX can be whatever you want it to be, as long as it’s not a duplicate rule name. Table 11-3 explains the arguments to the validateXXX( ) method. Table 11-3. The validateXXX( ) method arguments Parameter Description Object The JavaBean on which validation is being performed ValidatorAction The current ValidatorAction being performed Field The field object being validated ActionErrors The errors objects to add an ActionError to if the validation fails HttpServletRequest The current request object ServletContext The application’s ServletContext In most cases, the method should be static. However, you can define instance-level methods as well. Regardless of whether your methods are static, you must ensure that they are thread-safe. Example 113 illustrates a new validation rule that validates whether a String value is a valid boolean. Example 11-3. A validation rule that validates a boolean value import java.io.Serializable; import java.util.Locale; import javax.servlet.ServletContext;
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

depends=”required,mask”> mask ${phone} Now that we have everything (Web hosting faq)

Wednesday, August 29th, 2007

depends=”required,mask”> mask ${phone} Now that we have everything configured for the Storefront, it’s time to run the example. The nice thing about using a declarative approach versus a programmatic one is that once you have everything configured, you’re ready to go. The absence of programming makes the declarative approach much simpler. This is especially true for the Validator framework. There’s nothing to code, as long as the default validation rules satisfy your requirements. When we submit the shipping address page with no information in the fields, the validation rules kick in. The result is shown in Figure 11-3. Figure 11-3. The shipping address page using the Validator framework
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Virtual web hosting - The typeattribute specifies the exact ActionFormsubclass. In early

Tuesday, August 28th, 2007

The typeattribute specifies the exact ActionFormsubclass. In early beta releases of Struts 1.1, the form-bean section required that you set the dynamic attribute to true when using dynamic ActionForms. This is no longer necessary, as the framework will determine whether the class specified in the type attribute is a descendant of the DynaActionForm class. The next step is to edit the application-specific validation logic, which is done in the validation.xml file. You must declare a validation rule for each property in the form that you need to validate. In some cases, you might need to specify multiple rules. In Figure 11-2, for example, the phonefield is required, and it must fit a specific format. These are two separate rules that both must evaluate to true, or the validation for the form will fail. The entire validation.xml file is not shown because it’s too large and most of it is redundant. The section shown in Example 11-2 will help you understand how things are connected. Example 11-2. A sample validation.xml file for the checkout form
phone ^(?(d{3}))?[-| ]?(d{3})[ | ]?(d{4})$ zip ^d{5}(-d{4})?$

mask ^[a-zA-Z]*$ mask ${zip} 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.

For this example, we are going to use (Web hosting domain names)

Monday, August 27th, 2007

For this example, we are going to use a dynamic form. Therefore, we’ll use the DynaValidatorForm class to capture the shipping address details. Because the checkout process will span multiple pages and we want to capture this information across pages, we will need to configure the form bean to have session scope. We will also capture all of the checkout properties in a single ActionForm class. Instead of having a ShippingFormand a CreditCardForm, we will have a single form called CheckoutForm that captures all of the information. In our Struts configuration file, we set up the checkoutForm as shown here:
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

Apache web server - hierarchy in Figure 11-1, there are two versions

Sunday, August 26th, 2007

hierarchy in Figure 11-1, there are two versions of ValidatorForm. The parent class is called ValidatorForm, or DynaValidatorForm for the dynamic branch. Each of these has a subclass that contains the name Action in its title. The subclass of the ValidatorForm is called ValidatorActionForm , and the subclass of the DynaValidatorForm is called DynaValidatorActionForm . The purpose of the two different versions is to allow you to associate the validation with the form-bean definition or the action definition. The ValidatorActionFormand DynaValidatorActionForm classes pass the path attribute from the action element into the Validator, and the Validator uses the action’s name to look up the validation rules. If you use the ValidatorFormor DynaValidatorForm, the name of the ActionForm is used to look up the set of validation rules to use. The only reason for using one or the other is to have more fine-grained control over which validation rules are executed. For example, suppose that an ActionForm contains three different validation rules, but only two of them should get executed for a particular action. You could configure the rules to perform only the subset of validation rules when that action gets invoked. Otherwise, all of the rules would be invoked. In general, using ValidatorFormor DynaValidatorForm should be sufficient for your needs. Let’s look at a more complete example of using the Validator framework. As in previous chapters, we’ll employ the Storefront application to help us understand the Validator better. In particular, we’ll look at the HTML form used to capture the shipping information during checkout of the Storefront application. This is shown in Figure 11-2. Figure 11-2. Capturing the shipping address information
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

The Struts framework (Top web site) will call the init( )method

Saturday, August 25th, 2007

The Struts framework will call the init( )method in the ValidatorPlugIn class when the application starts up. During this method, the Validator resources from the XML files are loaded into memory so that they will be available to the application. Before calling the init( ) method, however, the pathnames property value is passed to the ValidatorPlugIn instance. This is how the ValidatorPlugIn finds out which Validator resources to load. For more information on how the PlugInmechanism works, see Section 9.2.1. 11.3 Using an ActionForm with the Validator You can’t use the standard Struts ActionForm class with the Validator. Instead, you need to use a subclass of the ActionForm class that is specifically designed to work with the Validator framework. There are two root subclasses to select from, depending on whether you are planning to use dynamic ActionForms. Figure 11-1 shows the ActionForm and its descendants, to help you visualize the hierarchy. Figure 11-1. The ActionForm class hierarchy If you are using dynamic ActionForms, you should use the DynaValidatorFormbranch of the hierarchy. If you are using standard ActionForms, you can use the ValidatorFormor one of its descendants instead. Whether you use dynamic or regular ActionForms, the manner in which you configure the Validator is the same. Just be sure that whichever ActionForm subclass you choose, you configure the form-bean section of the Struts configuration file using the fully qualified class name. See Section 4.7.2.2 for more details. Dynamic or standard is only the first decision that you have to make when choosing the proper ActionForm subclass. Notice that in both the dynamic and standard branch of the ActionForm
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

mask ${phone} minLength 5 The last of the

Friday, August 24th, 2007

mask ${phone} minLength 5 The last of the field child elements is the var element, as seen in Example 11-1 and in the previous fragment. The var element can set parameters that a field element may need to pass to one of its validation rules, such as the minimum and maximum values in a range validation. These parameters may also be referenced by one of the argelements using a shell syntax: ${var:varname}. In Example 11-1, the substituted value for the phone constant is passed into the mask validation rule so that it can be used to check whether the property value conforms to the proper phone mask. The field element can have zero or more var elements. Once you have the two XML resource files configured for your application, you need to place them in the WEB-INF directory. They will be referenced within the Struts configuration file, as described in the next section. 11.2.3 Plugging In the Validator Each Struts application needs to know that the Validator framework is being employed. As discussed in Chapter 9, you can use the PlugIn mechanism to hook the Validator framework into a Struts application. Earlier versions of the Validator used an extra servlet to inform the Struts application that the Validator components were present. The ValidatorServlet has been deprecated and should not be used. The following fragment illustrates how to set up the Validator as a plug-in:
There was some confusion in one of the earlier beta releases for the Validator that used multiple set-property elements. That is no longer supported you should use a single set-property element that specifies multiple Validator resource files, separated by commas. Also notice that the property value is the plural pathnames.
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

mappings, where each action mapping may depend on (Affordable web hosting)

Thursday, August 23rd, 2007

mappings, where each action mapping may depend on only certain form fields to be validated and the others to be left alone. The fieldelement contains several child elements: The msgchild element allows you to specify an alternate message for a field element. The validation rule can use this value instead of the default message declared with the rule. The value for the msg element must be a key from the application resource bundle. For example: mask ${phone} The msgelement supports three attributes: The nameattribute specifies the rule with which the msg should be used. The value should be one of the rules specified in the validation-rules.xml file or in the global section. The keyattribute specifies a key from the resource bundle that should be added to the ActionError if validation fails. If you want to specify a literal message, rather than using the resource bundle, you can set the resource attribute to false. In this case, the key attribute is taken as a literal string. The fieldelement allows up to four additional elements to be included. These elements, named arg0, arg1, arg2, and arg3, are used to pass additional values to the message, either from the resource bundle or from the varor constant elements. The arg0 element defines the first replacement value, arg1defines the second replacement value, and so on. Each arg element supports three attributes, name, key, and resource, which are the same as the attributes of the msg element described earlier. Example 11-1 included elements for arg0and arg1 like this:
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

The formset element supports two attributes that (Managed web hosting) deal

Wednesday, August 22nd, 2007

The formset element supports two attributes that deal with I18N, languageand country: If you don’t have any I18N requirements for your validation routines and want to use the default locale, you can leave out these attributes. The section Section 11.6″ later in this chapter discusses this topic in more detail. The form element defines a set of fields to be validated. The namecorresponds to the identifier the application assigns to the form. In the case of the Struts framework, this is the name attribute from the form-beans section. The formelement defines a set of fields that are to be validated. It contains a single attribute name, which should match one of the nameattributes from the form-beans section of the Struts configuration file. The formelement can contain one or more field elements: The field element corresponds to a specific property of a JavaBean that needs to be validated. In a Struts application, this JavaBean is an ActionForm. In Example 11-1, the sole field element for the checkoutForm corresponds to the phoneproperty in an ActionForm called checkoutForm in the form-beans section of the Struts configuration file. The field element supports several attributes, which are listed in Table 11-2. Table 11-2. The attributes of the field element Attribute Description property The property name of the JavaBean (or ActionForm) to be validated. depends The comma-delimited list of validation rules to apply against this field. For the field to succeed, all the validators must succeed. page The JavaBean corresponding to this form may include a pageproperty. Only fields with a page attribute value that is equal to or less than the value of the page property on the form JavaBean are processed. This is useful when using a “wizard” approach to completing a large form, to ensure that a page is not skipped. indexedListPropertyThe method name that will return an array or a Collectionused to retrieve the list and then loop through the list, performing the validations for this field. Both the ValidatorActionFormand DynaValidatorActionFormmatch on the action mapping rather than the form name. That is, instead of matching on the form name in the name attribute of the form element, you can use the path attribute of the action element. This allows the same form to be used for different action
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.