我使用相同的bean字段,一个名为email的字符串,用于不同的目的(注册,恢复密码,登录)。所以,我希望在视图/流和bean字段之间导航必须自动清理,但这种情况不会发生。
这是一个JSF2 / Spring项目
流程定义
<var name="viewScope.loginFields" class="es.project.viewBean.ConnectionFields" />
<view-state id="login" view="login.xhtml" model="loginFields">
<transition on="entry" to="connect"/>
<transition on="recoveryPass" to="recovery" />
</view-state>
<view-state id="recovery" view="recovery.xhtml" model="loginFields">
<transition on="return" to="login" />
<transition on="sendPass" to="recoveryPass" />
</view-state>
Bean定义
@Service("loginFields")
public class ConnectionFields implements Serializable {
private static final long serialVersionUID = 1L;
private static Logger logger=LogManager.getLogger(ConnectionFields.class);
@NotNull(message="{field.notEmpty.validation}")
@Email(message="{field.email.validation}")
private String email;
@NotNull(message="{field.notEmpty.validation}")
@Size(min=6,max=12,message="{field.size.validation}")
@Pattern(regexp="^[a-zA-Z0-9]*$",message="{field.onlyAlpha.validation}")
private String password;
@NotNull(message="{field.notEmpty.validation}")
@Size(min=6,max=12,message="{field.size.validation}")
@Pattern(regexp="^[a-zA-Z0-9]*$",message="{field.onlyAlpha.validation}")
private String passwordRepeated;
@NotNull(message="{field.notEmpty.validation}")
@Email(message="{field.email.validation}")
private String emailRepeated;
...........
...........
...........
}
recovery.xhtml
<h:form id="formRecovery">
<h:panelGroup layout="block" id="containerFormRecovery" styleClass="containerFormRecovery">
<p:focus />
<h:panelGroup layout="block" styleClass="formRecovery-row">
<h:outputLabel for="email" value="#{msg['email.txt']}" />
<h:inputText id="email" value="#{loginFields.email}" title="#{msg['email.txt.title']}" alt="#{msg['email.txt.alt']}" styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="1">
<f:validateBean for="email" />
<p:ajax event="blur" update="@this emailError"/>
</h:inputText>
<h:message for="email" id="emailError" styleClass="messageError" />
</h:panelGroup>
<h:panelGroup layout="block" styleClass="formRecovery-row">
<p:captcha id="captcha" theme="white" requiredMessage="#{msg['captcha.required']}" tabindex="2">
</p:captcha>
<h:message for="captcha" id="captchaError" styleClass="messageError"/>
</h:panelGroup>
<h:panelGroup layout="block" id="containerRecoveryButtons" styleClass="containerRecoveryButtons">
<h:commandButton value="#{msg['send.btn']}" title="#{msg['send.btn.title']}" alt="#{msg['send.btn.title']}" action="sendPass" tabindex="3" />
</h:panelGroup>
</h:panelGroup>
</h:form>
<h:panelGroup>
<h:commandLink value="#{msg['return.btn']}" title="#{msg['return.btn.title']}" alt="#{msg['return.btn.alt']}" action="return" tabindex="4" />
</h:panelGroup>
login.xthml
<h:form id="formLogin">
<h:panelGroup layout="block" id="containerFormLogin" styleClass="containerFormLogin">
<p:focus />
<h:panelGroup layout="block" styleClass="formLogin-row">
<h:outputLabel for="email" value="#{msg['email.txt']}" />
<h:inputText id="email" value="#{loginFields.email}" title="#{msg['email.txt.title']}" alt="#{msg['email.txt.alt']}" styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="2">
<f:validateBean for="email" />
<p:ajax event="blur" update="@this emailError" />
</h:inputText>
<h:message for="email" id="emailError" styleClass="messageError" />
</h:panelGroup>
<h:panelGroup layout="block" styleClass="formLogin-row">
<h:outputLabel for="password" value="#{msg['pass.txt']}" />
<p:password id="password" value="#{loginFields.password}" title="#{msg['pass.txt.title']}" alt="#{msg['pass.txt.alt']}"
styleClass="#{component.valid ? '' : 'invalid'}" size="35" tabindex="3">
<f:validateBean for="password" />
<p:ajax event="blur" update="@this passwordError" />
</p:password>
<h:message for="password" id="passwordError" styleClass="messageError" />
</h:panelGroup>
<p>
<h:outputLabel for="remember" value="#{msg['rememberSession.msg.check']}" />
<h:selectBooleanCheckbox id="remember" value="#{loginFields.remember}" tabindex="4" title="#{msg['rememberSession.title.check']}" />
</p>
<h:panelGroup layout="block" id="containerLoginButtons" styleClass="containerLoginButtons">
<h:commandButton value="#{msg['login.long.btn']}" action="entry" tabindex="5" title="#{msg['login.long.btn.title']}" alt="#{msg['login.long.btn.alt']}" />
</h:panelGroup>
</h:panelGroup>
</h:form>
<p>
<h:form>
<h:commandLink value="#{msg['recoveryPassword.msg.link']}" action="recoveryPass" />
</h:form>
</p>
在上面的示例中,我的想法是从登录页面导航到RecoveryPassword页面,反之亦然,当我更改视图时,我希望电子邮件字段重置值本身,但电子邮件永远不会重置值。
答案 0 :(得分:1)
一种方法是清除州内<transition>
或<on-entry>
的值。使用setter方法或使用自定义方法(例如reset()
)。我们这样做是为了进入一个州需要清理一个领域的各种其他条件。
e.g。
<view-state id="recovery">
<on-entry>
<set name="loginFields.email" value="''"/>
</on-entry>
...
</view-state>