我有一个带注释的服务bean,用于在 newSpace_1页面上存储表单值,当我导航到另一个流程时我希望清理这个bean,因为如果我返回 newSpace_1页面我想显示空字段,因为我得到的导航按钮取决于字段的值。
我尝试将此bean声明为var on flow definition和@service bean,然后set方法可以工作,但get方法为每个属性检索null。所以我需要使用@service作为set / get方法在 newSpace_1页上正常工作。
<flow...>
<var name="spaceFields" class="x.y.x.Spacields" />
<view-state>
......
</view-state>
</flow>
SpaceFields
@Service("spaceFields")
public class SpaceFields implements Serializable {
private static final long serialVersionUID = 1L;
@Min(value=1)
@Max(value=194)
private Integer idCountry;
@Min(value=1)
@Max(value=5)
private Integer idContinent;
....
....
}
流程定义
<?xml version="1.0" encoding="UTF-8"?>
<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"
parent="commons-header">
<secured attributes="ROLE_USER" />
<view-state id="adminSpace" view="admin_spaces.xhtml">
<transition on="new" to="step1" />
</view-state>
<view-state id="step1" view="newSpace_1.xhtml">
<on-entry>
<evaluate expression="place.findContinents()" result="flowScope.continents" />
</on-entry>
<transition on="next" to="step2" />
</view-state>
<view-state id="step2" view="newSpace_2.xhtml">
<on-entry>
<evaluate expression="category.findCategories()" result="flowScope.categories" />
</on-entry>
<transition on="back" to="step1" />
<transition on="next" to="step3" />
</view-state>
<view-state id="step3" view="newSpace_3.xhtml">
<transition on="back" to="step2" />
<transition on="next" to="step4" />
</view-state>
newSpace_1代码
<ui:composition template="/WEB-INF/templates/mainPage.xhtml">
<ui:define name="title">
<h:outputText value="${msg['newSpace.title']}" />
</ui:define>
<ui:define name="centerContainer">
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_info" styleClass="creatingSpaceContainer_step1_info">
<h1>
<h:outputText value="#{msg['newSpace.step1.main.header']}" />
</h1>
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_info_msg" styleClass="creatingSpaceContainer_step1_info_msg">
<h:outputText value="#{msg['newSpace.step1.main.msg']}" />
</h:panelGroup>
</h:panelGroup>
<h:form>
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_fields" styleClass="creatingSpaceContainer_step1_fields">
<h:outputLabel for="continent" value="#{msg['continent.txt']}" styleClass="labelInput" />
<h:selectOneMenu id="continent" value="#{spaceFields.idContinent}" title="#{msg['continent.select.title']}" tabindex="1">
<f:selectItem itemLabel="#{msg['continent.select.zeroption']}" itemValue="0" noSelectionOption="true" />
<f:selectItems var="continent" value="#{continents}" itemLabel="#{continent.name}" itemValue="#{continent.primaryKey.continent.idContinent}" />
<f:ajax render="@this country messageContinentError" listener="#{place.findCountries(flowRequestContext)}" event="change" />
<f:validateBean for="idContinent" />
</h:selectOneMenu>
<h:message id="messageContinentError" for="continent" styleClass="messageError" />
<h:outputLabel for="country" value="#{msg['country.txt']}" styleClass="labelInput" />
<h:selectOneMenu id="country" value="#{spaceFields.idCountry}" title="#{msg['country.select.title']}" tabindex="2">
<f:selectItem itemLabel="#{msg['country.select.zeroption']}" itemValue="0" noSelectionOption="true" />
<f:selectItems var="countryLocale" value="#{countries}" itemLabel="#{countryLocale.name}" itemValue="#{countryLocale.primaryKey.country.idCountry}" />
<f:ajax render="@this -controls-creatingSpaceContainer_step1_controls messageCountryError" event="change" />
<f:validateBean for="idCountry" />
</h:selectOneMenu>
<h:message id="messageCountryError" for="country" styleClass="messageError" />
</h:panelGroup>
</h:form>
<h:form id="controls">
<h:panelGroup layout="block" id="creatingSpaceContainer_step1_controls" styleClass="creatingSpaceContainer_step1_controls">
<h:commandLink action="next" value="#{msg['next.button.txt']}" title="#{msg['next.button.title']}" alt="#{msg['next.button.alt']}" tabindex="3" rendered="#{spaceFields.idCountry>0}" />
</h:panelGroup>
</h:form>
</ui:define>
</ui:composition>
答案 0 :(得分:1)
在视图状态下使用退出操作以在远离视图时清除bean:
<view-state id="step1" view="newSpace_1.xhtml">
<on-entry>
....
</on-entry>
<transition on="next" to="step2">
<on-exit>
<evaluate expression="someaction.clear(flowScope.spaceFields)"/>
</on-exit>
</view-state>
这样当你重新进入视图时,你所有的bean字段都是空的。
您可以找到有关退出操作here的详细信息。