spring-roo 2.0 Spring Webflow Persistence Best Practise


spring-roo 2.0 Spring Webflow Persistence Best Practise



I am having troubles with persisting an entity in a web flow with Spring Roo 2.0.0.RC2.



With Roo 2.0, I have generated an application which shall register a user at the end of a webflow.



Here are my roo commands:


entity jpa --class ~.model.AppUser --serializable
field string --fieldName username --notNull
web flow --flowName registrationProcess --class ~.RegistrationProcessFormBean`



This is my flow.xml:




<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" start-state="create-appuser" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd">

<persistence-context />

<on-start>
<set name="flowScope.registrationProcessFormBean" value="new de.xx.www.training.RegistrationProcessFormBean()"/>
<set name="flowScope.appUser" value="new de.xx.www.training.model.AppUser()"/>
</on-start>

<view-state id="create-appuser" model="appUser" view="registrationprocess/create-appuser">
<transition on="success" to="end-state" />
</view-state>

<end-state id="end-state" view="registrationprocess/end-state" commit="true"/>

</flow>



Note: I am aware that it is better to use a dto instead of an entity. Currently, I am just trying to find a simple way to persist the entity AppUser.



My questions:



Please advise. Thanks in advance!




1 Answer
1



First define your entities and generate repository and service layers :


entity jpa --class ~.model.MyBean --serializable
repository jpa --all --package ~.repository
service --all --apiPackage ~.service.api --implPackage ~.service.impl



Now your service bean (myBeanServiceImpl) is available in the context.


myBeanServiceImpl



You can use it to save your entity as follow in your flow:


<view-state id="view-state-1" view="gocluster/view-state-1" model="basics">
<transition on="success" to="view-state-2">
<evaluate expression="myBeanServiceImpl.save(basics)" result="flowScope.someObjectData" />
</transition>
</view-state>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages