Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
DTO in AppFuse using XSnapshotPart I: Integrating XSnapshot in AppFuse - A HowTo for integrating the XSnapshot framework in AppFuse About this TutorialThis tutorial will show you how to integrating the XSnapshot framework into Appfuse. By default, in Appfuse, the forms and generated by the XDoclet task @struts.form, and the data transfert used the jakarta commons beanutils. With XSnapshot, the form is always generated by a set of xdoclet tasks which generate a snapshot and a helper class that convert data between model and form classes. Table of Contents
Download the latest version Xsnapshot[#1]First of all we need to Download the XSnapshot framework. Howerer, the "official" framework can't be integrated in the Struts version of AppFuse for a simple raison : generated Struts form contain not the doclet @struts.form name="..."
In this form generated example, for AppFuse, it should have a doclet @struts.form name="personForm". In this case, appfuse tasks would not be able to generate the struts-config.xml. So I have modifie the XSnapshot sources, in particular the net/sf/xsnapshot/ressources/snapshot.xdt to add the doclet. NOTE: xsnapshot form generation does not write the struts validator doclet write in the model classes sources so you can not use Struts validator :-(. I am looking to modifie xsnapshot sources...So download this version of xsnapshot Integrate the libraries in AppFuse[#2]
# # xsnapshot - http://xsnapshot.sourceforge.net # xsnapshot.version=1.1-beta2 xsnapshot.dir=${lib.dir}/xsnapshot-${xsnapshot.version} xsnapshot.jar=${xsnapshot.dir}/xsnapshot.jar
So the commons part would be like that # # Commons - http://jakarta.apache.org/commons # commons.dir=${lib.dir}/jakarta-commons commons-beanutils.jar=${commons.dir}/commons-beanutils.jar commons-collections.jar=${commons.dir}/commons-collections.jar # New for XSnapshot commons-configuration.jar=${commons.dir}/commons-configuration.jar commons-digester.jar=${commons.dir}/commons-digester.jar commons-fileupload.jar=${commons.dir}/commons-fileupload.jar commons-lang.jar=${commons.dir}/commons-lang.jar commons-logging.jar=${commons.dir}/commons-logging.jar commons-validator.jar=${commons.dir}/commons-validator.jar jakarta-oro.jar=${commons.dir}/jakarta-oro.jar
<path id="xsnapshot.classpath"> <fileset dir="${xsnapshot.dir}" includes="*.jar"/> <fileset dir="${xdoclet.dir}"> <include name="*.jar"/> </fileset> <pathelement location="${j2ee.dir}/lib/j2ee.jar"/> <pathelement location="${ant.home}/lib/ant.jar"/> <pathelement location="${commons-collections.jar}"/> <pathelement location="${commons-logging.jar}"/> <pathelement location="${commons-lang.jar}"/> </path>
Add this line in your properties.xml file at the end of <pathelement location="${xsnapshot.jar}"/> Integrate new XSnapshot ANT-Tasks in the build.xml [#3]In order to use cobertura with your junit tests, you have to add the cobertura ANT-tasks to your build.xml
<target name="gen-snapshotforms" description="Builds xsnapshots files, if necessary" depends=""> <taskdef name="xsnapshotdoclet" classname="net.sf.xsnapshot.ant.XSnapshotDocletTask" classpathref="xsnapshot.classpath"/> <xsnapshotdoclet destdir="${build.dir}/web/gen" verbose="true" mergedir="${xdoclet.merge.dir}" > <fileset dir="src/dao" includes="**/*.java"/> <packageSubstitution packages="model" substituteWith="webapp.form"/> <snapshot/> <helper/> </xsnapshotdoclet> <xsnapshotdoclet destdir="${build.dir}/web/gen" verbose="true" mergedir="${xdoclet.merge.dir}" > <fileset dir="src/dao" includes="**/*.java"/> <packageSubstitution packages="model" substituteWith="webapp.form"/> <properties/> </xsnapshotdoclet> </target> The first line defines the xsnapshot doclet task, using the classpath defined before. The xsnapshotdoclet
task defines three subtasks, Best practice is to have the the source XSnapshot quickstart guide
<antcall target="gen-snapshotforms" /> Add XSnapshot files in the WAR [#4]
<lib file="${xsnapshot.jar}"/> <lib file="${commons-configuration.jar}" /> <webinf file="${build.dir}/web/gen/xsnapshot.properties" /> Declare XSnapshot Beans in the Spring container [#5]
A transformer specify how to transform a value of a property in a model to the value the matching property should have in a snapshot, or the reverse transformation. We will see later a Date-to-Input transformer for transforming Date into String. Add the following into src/service/org/appfuse/service/applicationContext-service.xml <!-- SPECIAL DAO for transforming IDs to entities of arbitrary class --> <bean id="id-to-entity" parent="dao" class="net.sf.xsnapshot.hibernate3.IdToEntityTransformer"/> The id-to-entity transformer is used to retrieve a Object by is id using a dao
Add the following part <!-- ======================== XSNAPSHOT SETUP ========================= --> <bean id="xsnapshotRegistry" class="net.sf.xsnapshot.spring.XSnapshotRegistryFactoryBean"> <property name="configLocations"> <list> <value>/WEB-INF/xsnapshot.properties</value> </list> </property> <property name="helperMappings"> <map> </map> </property> <property name="transformerMappings"> <map> <!-- invoked indirectly by xsnapshot --> <entry key="inverse-nested-property" value-ref="id-to-entity"/> </map> </property> </bean>
The XsnapshotUtils class contains methods for working with XSnapshot at runtime <bean id="xsnapshotUtils" class="net.sf.xsnapshot.XSnapshotUtils"> <property name="registry" ref="xsnapshotRegistry"/> </bean>
Everything should run normaly.... like would say Matt You are ready to use Xsnapshot in our Appfuse Project Next Up: Part II: Implementing the example Attachments:
|