Adding Spice to Struts

Reviews : Adding Spice to Struts :

The Final Solution…

The final solution we came up with will include an extra <form-property> named "includes" specifying the form bean name to be included. Thus, the new solution will look like this:


<form-bean
name="ShipForm" type="our own form bean">

<form-property name="includes"
type="java.lang.String" initial="anotherForm"/>

</form-bean>

This new <form-property> must have the name "includes" and the initial value of this property must hold the name of the form bean that we want to include. With this idea in mind, we ventured to write a new ActionForm class.

The CustomDynaForm class

We decided to create a class called CustomDynaForm, which will extend the original Struts DynaActionForm class. We will override the initialize() method of the DynaActionForm class to include all the properties from another form bean. Listing –2 is the source code for the new CustomDynaForm class.


package custom.struts;

import org.apache.struts.action.DynaActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.FormBeanConfig;
import org.apache.struts.config.FormPropertyConfig;
public class CustomDynaForm extends DynaActionForm
{
     /**
      * override the initialize() method
     */
    public void initialize(ActionMapping mapping)
    {
        super.initialize(mapping);

        //form bean name

        String name = mapping.getName();

        //form bean config

     FormBeanConfig config = mapping.getModuleConfig()
.findFormBeanConfig(name);

        //now check if there is "includes" property

        FormPropertyConfig propConfig = config.findFormPropertyConfig("includes");
        if (propConfig != null)
        {
              //get the initial values
        String formBeanToInclude = propConfig.getInitial();
        FormBeanConfig formBeanConfig =
        mapping.getModuleConfig().findFormBeanConfig(formBeanToInclude);
        FormPropertyConfig properties[] =
        formBeanConfig.findFormPropertyConfigs();
            for (int i = 0; i < properties.length; i++)
            {
                //set(properties[i].getName(), properties[i].initial());

                this.getMap().put(properties[i].getName(), properties[i].getInitial());
            }
        }
    }
}

Listing 2: The CustomDyaForm source code

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.