kax
Aug 9th, 2005, 02:57 PM
Hi,
I have a question regarding best practicies and Spring Web Flow. Say I have a CRUD action for a Person object, called PersonCrudAction,
which contains methods for creating, reading, updating and deleting a Person. If I ,for example, want to create a new Person object I
have seen different approches for how to "structure" the actions.
One way looks like this (the configuration isn't complete but I think you get it anyway):
<webflow>
<view-state id="personForm" view="person.Search.criteria.view">
<setup bean="person.formAction" method="setupForm"/>
<transition on="submit" to="createPerson">
<action bean="person.formAction" method="bindAndValidate"/>
</transition>
</view-state>
<action-state id="createPerson">
<action bean="personCrud" method="create"/>
<transition on="success" to="displayPerson"/>
</action-state>
</webflow>
<beans>
<bean id="person.formAction"
class="org.springframework.web.flow.action.FormAction">
<property name="formObjectName" value="model"/>
<property name="formObjectClass" value="my.project.Person"/>
<property name="formObjectScopeAsString" value="flow"/>
</bean>
<bean id="personCrud" class="my.project.PersonCrudAction"/>
</beans>
In this case the PersonCrudAction extends the SWF MultiAction class.
In some other examples I have seen a different approch which looks something like this:
<webflow>
<view-state id="personForm" view="person.Search.criteria.view">
<setup bean="personCrud" method="setupForm"/>
<transition on="submit" to="createPerson">
<action bean="personCrud" method="bindAndValidate"/>
</transition>
</view-state>
<action-state id="createPerson">
<action bean="personCrud" method="create"/>
<transition on="success" to="displayPerson"/>
</action-state>
</webflow>
<beans>
<bean id="personCrud" class="my.project.PersonCrudAction">
<property name="formObjectName" value="model"/>
<property name="formObjectClass" value="my.project.Person"/>
<property name="formObjectScopeAsString" value="flow"/>
</bean>
</beans>
In this case the PersonCrudAction extends the SWF FormAction class and you don't declare a FormAction bean but rather use
PersonCrudAction for the binding as well as executing the logic of creating a new Person.
The second approach is more compact than the first one but are there any drawbacks in using this approach? Which approach can be seen as
best practice? And why?
Thanks in advance
/Kax
I have a question regarding best practicies and Spring Web Flow. Say I have a CRUD action for a Person object, called PersonCrudAction,
which contains methods for creating, reading, updating and deleting a Person. If I ,for example, want to create a new Person object I
have seen different approches for how to "structure" the actions.
One way looks like this (the configuration isn't complete but I think you get it anyway):
<webflow>
<view-state id="personForm" view="person.Search.criteria.view">
<setup bean="person.formAction" method="setupForm"/>
<transition on="submit" to="createPerson">
<action bean="person.formAction" method="bindAndValidate"/>
</transition>
</view-state>
<action-state id="createPerson">
<action bean="personCrud" method="create"/>
<transition on="success" to="displayPerson"/>
</action-state>
</webflow>
<beans>
<bean id="person.formAction"
class="org.springframework.web.flow.action.FormAction">
<property name="formObjectName" value="model"/>
<property name="formObjectClass" value="my.project.Person"/>
<property name="formObjectScopeAsString" value="flow"/>
</bean>
<bean id="personCrud" class="my.project.PersonCrudAction"/>
</beans>
In this case the PersonCrudAction extends the SWF MultiAction class.
In some other examples I have seen a different approch which looks something like this:
<webflow>
<view-state id="personForm" view="person.Search.criteria.view">
<setup bean="personCrud" method="setupForm"/>
<transition on="submit" to="createPerson">
<action bean="personCrud" method="bindAndValidate"/>
</transition>
</view-state>
<action-state id="createPerson">
<action bean="personCrud" method="create"/>
<transition on="success" to="displayPerson"/>
</action-state>
</webflow>
<beans>
<bean id="personCrud" class="my.project.PersonCrudAction">
<property name="formObjectName" value="model"/>
<property name="formObjectClass" value="my.project.Person"/>
<property name="formObjectScopeAsString" value="flow"/>
</bean>
</beans>
In this case the PersonCrudAction extends the SWF FormAction class and you don't declare a FormAction bean but rather use
PersonCrudAction for the binding as well as executing the logic of creating a new Person.
The second approach is more compact than the first one but are there any drawbacks in using this approach? Which approach can be seen as
best practice? And why?
Thanks in advance
/Kax