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!
I did as suggested.
<on-start>
<set name="flowScope.appUser" value="new de.test.model.AppUser()"/>
</on-start>
<!-- A sample view state -->
<view-state id="view-state-1" model="appUser" view="registrationprocess/view-state-1">
<transition on="success" to="view-state-2">
<evaluate expression="appUserServiceImpl.save(appUser)" result="flowScope.appUser" />
</transition>
</view-state>
org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 19): Method call: Method save(de.test.model.AppUser) cannot be found on de.test.service.impl.AppUserServiceImpl$$EnhancerBySpringCGLIB$$10b2028b type
What am I doing wrong?
The method exists.
public class AppUserServiceImpl implements AppUserService {
public AppUser save(AppUser entity) {
return getAppUserRepository().save(entity);
}
Thank you for some hints.
As a work around, I disabled spring-boot-devtools in pom.xml (see https://github.com/spring-projects/spring-boot/issues/7912).
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.
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>