Re: Generating ActionForms

From: Mike Kienenberger (mkienen..laska.net)
Date: Thu Jul 01 2004 - 17:40:57 EDT

  • Next message: Michele Cuozzo: "flattened relationships"

    Scott McClure <scot..martblob.com> wrote:
    > I was wondering how simple it would be to extend the current DataObject
    > generation tasks/interface to allow to create ActionForms as well.
    ActionForms
    > are Struts classes that closely mirror the model classes. Even if they
    would
    > need to be edited (validation added, fields removed, etc.), It would be
    much
    > nicer to have a chance to build the initial files from Cayenne.
    >
    > All that is needed from Cayenne is to run one more Velocity template.

    Take a look at this for the patches.

    http://objectstyle.org/jira/secure/ViewIssue.jspa?key=CAY-79

    Then you can do things like the following. I have templates for
    validation.xml and for *Action.java as well.

    ============================================================================

        <!-- Rebuild classes dependent on database model -->
        <target name="generateEditEntityPart4" depends="init"
    description="cmd-line: Generates EditENTITYEntity-struts-config.xml">
                    <taskdef name="cgen"
    classname="org.objectstyle.cayenne.tools.CayenneGenerator">
                         <classpath refid="generate.classpath"/>
                    </taskdef>
                    <cgen
    map="${local.project.location}/Ebpp-struts/WEB-INF/OnlineBilling.map.xml"
                              filenamePrefix="Edit"
                              filenameSuffix="Entity-struts-config.xml"
                              entity="${ENTITY_NAME}"
                              overwrite="false"
                          
    destDir="${local.project.location}/Ebpp-struts/WEB-INF/pages/generated"
                          makepairs="false"
                          
    template="${local.project.location}/Ebpp-struts/WEB-INF/src/support/VelocityEditEntityComponent/VelocityEditEntityComponent.struts-
    config.vm"
                          usepkgpath="false"
                    />
        </target>

    ============================================================================

    #set( $dollarSign = '$' )
    #set( $poundSign = '#' )
    #set( $CapitializedEntityName =
    ${classGen.capitalizeString($classGen.Entity.name)})
    #set( $unCapitializedEntityName =
    ${classGen.uncapitalizeString($classGen.Entity.name)})
    <?xml version="1.0" encoding="ISO-8859-1" ?>

    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
              "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>

        <form-beans>

                    <form-bean
                name="edit${CapitializedEntityName}EntityForm"
                
    type="org_apache_struts_validator.NullConvertingDynaValidatorForm">
    #foreach ( $attribute in $classGen.Entity.Attributes )##
    #set ($capitalizedAttribute =
    ${classGen.capitalizeString($attribute.name)})##
    #set ($uncapitalizedAttribute =
    ${classGen.uncapitalizeString($attribute.name)})##
    #if ($attribute.Type == "java.lang.Boolean")##
                <form-property
                    name="$uncapitalizedAttribute"
                    type="java.lang.Boolean"/>
    #else## ($attribute.Type == "java.lang.Boolean")##
                <form-property
                    name="$uncapitalizedAttribute"
                    type="java.lang.String"/>
    #end## ($attribute.Type == "java.lang.Boolean")##
    #end## ( $attribute in $classGen.Entity.Attributes )
                    </form-bean>
                    

        </form-beans>

        <action-mappings>

                     <action path="/Edit${CapitializedEntityName}Entity"
                            
    type="com.gvea.struts.ebpp.action.generated.InitializeEdit${CapitializedEntityName}EntityAction"
                            scope="request"
                                    name="edit${CapitializedEntityName}EntityForm"
                                    validate="false"
                                    input="/vm/Edit${CapitializedEntityName}Entity.do">
                                <forward name="Success"
    path="/vm/Edit${CapitializedEntityName}Entity.do"/>
                    </action>
     
                     <action path="/Edit${CapitializedEntityName}EntityResult"
                            
    type="com.gvea.struts.ebpp.action.generated.Edit${CapitializedEntityName}EntityAction"
                            scope="request"
                                    name="edit${CapitializedEntityName}EntityForm"
                                    validate="true"
                                    input="/vm/Edit${CapitializedEntityName}Entity.do">
                                <forward name="Success"
    path="/vm/Edit${CapitializedEntityName}Entity.do"/>
                                <forward name="Failure"
    path="/vm/Edit${CapitializedEntityName}Entity.do"/>
                    </action>
                    

                    <action path="/vm/Edit${CapitializedEntityName}Entity"
                     type="us_ok_deq_wqdata.http.ViewAction"
                     validate="false"
                     
    parameter="IsExternal;ShouldShowReturnToLastPageLink;Title;leftSideMenu;loginPanel;header;body;footer">

                       <forward name="IsExternal" path="false" />
                       <forward name="Title" path="Golden Valley Electric Association - Online
    Bill Payment - Edit ${CapitializedEntityName}" />
                       <forward name="body"
    path="/WEB-INF/pages/generated/Edit${CapitializedEntityName}Entity.vm" />
                    </action>
                    
            </action-mappings>

    </struts-config>

    ============================================================================



    This archive was generated by hypermail 2.0.0 : Thu Jul 01 2004 - 17:40:45 EDT