我正在用Spring Roo编写一个带有MVC和持久性支持的Spring webflow。在这个流程中,用户应该创建一个实体的多个实例,而这个实例又是从另一个实体引用的。为了简单起见,我将复制这些实体MyClass1和MyClass2。我很难弄清楚如何保留持久实体列表,这在确认时需要。使用Spring Webflow 2.0在jspx中丢失了一个ArrayList中的持久实体
我以前发布过关于同一主题的question。不过,我确实认为为了进一步澄清我的问题而编辑原始问题(甚至更多)会违反SO-“议定书”,因此我决定提出原始问题的精炼版本。回想起来,我意识到原来的问题应该更加准确。我可能会为此得到一些热量,但我觉得这个问题足够重要(至少对我来说)。 :)
我包括我的roo脚本让任何人都可以轻松地重现我的设置。那就是:
project --topLevelPackage com.test.webflow
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
entity --class ~.domain.Class1 --testAutomatically
field string --fieldName name
entity --class ~.domain.Class2 --testAutomatically
field string --fieldName name
field reference --fieldName class1 --type ~.domain.Class1
controller scaffold --class ~.web.Class1Controller --entity ~.domain.Class1
controller scaffold --class ~.web.Class2Controller --entity ~.domain.Class2
web flow --flowName registration
在/ WEB-INF /视图/登记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" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<on-start>
<evaluate expression="new java.util.ArrayList()" result="flowScope.myList" result-type="java.io.Serializable"/>
</on-start>
<view-state id="view-state-1" view="registration/view-state-1" model="class1">
<on-entry>
<evaluate expression="new com.test.webflow.domain.Class1()" result="flowScope.class1"/>
</on-entry>
<transition on="repeat" to="view-state-1"/>
<transition on="success" to="view-state-2"/>
<transition on="cancel" to="end-state"/>
<on-exit>
<evaluate expression="class1.persist()" result="flowScope.class1"/>
<evaluate expression="myList.add(class1)"/>
</on-exit>
</view-state>
<view-state id="view-state-2" view="registration/view-state-2">
<transition on="cancel" to="end-state"/>
</view-state>
<end-state id="end-state" view="registration/end-state"/>
</flow>
(在流动的现实版,会有另。视图状态中的Class2的实体将被注册)的view-state-1.jspx
看起来是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<spring:message var="title" code="webflow_state1_title" htmlEscape="false" />
<util:panel id="title" title="${title}">
<h1>${fn:escapeXml(title)}</h1>
<p>
<spring:message code="webflow_state1_message" />
</p>
<form:form commandName="class1">
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}" />
<p>Enter name: <form:input path="name"/></p>
<div class="submit">
<spring:message var="cancel" code="button_cancel" htmlEscape="false" />
<spring:message var="proceed" code="button_proceed" htmlEscape="false" />
<spring:message var="repeat" code="button_repeat" htmlEscape="false" />
<input type="submit" id="cancel" name="_eventId_cancel" value="${fn:escapeXml(cancel)}" />
<input type="submit" id="success" name="_eventId_success" value="${fn:escapeXml(proceed)}" />
<input type="submit" id="repeat" name="_eventId_repeat" value="${fn:escapeXml(repeat)}" />
</div>
</form:form>
</util:panel>
</div>
的view-state-2.jspx
看起来是这样的:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:spring="http://www.springframework.org/tags" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:output omit-xml-declaration="yes" />
<spring:message var="title" code="webflow_state2_title" htmlEscape="false" />
<util:panel id="title" title="${title}">
<h1>${fn:escapeXml(title)}</h1>
<p>
<spring:message code="webflow_state2_message" />
</p>
<p>
<c:forEach var="class1" items="${myList}">
<li><c:out value="${class1.name}"/></li>
</c:forEach>
</p>
</util:panel>
</div>
从我读过的所有内容来看,我认为我的解决方案应该可以工作。但是,我仍然没有得到预期的结果;即每个name
字段中的打印输出。正如我放入的那样,我得到了相同数量的<li> -elements,但他们似乎都被评估为空,正如我以前的帖子所解释的。任何人都可以向我解释为什么这段代码不显示持久化Class1.name字段的内容? (顺便说一句:他们确实出现在CRUD中。)
在此先感谢!