我有这个jsf代码
<h:form>
<h:inputText value="#{agreement.serviceId}"/>
<h:commandButton value="Enter" action="#{agreement.build}" />
<h:form rendered="#{!agreement.valid}">
<h:outputText value="Service id not valid. Please try again"/>
</h:form>
<h:form>
这是作用域 bean 的构建方法。
public String build(){
try{
...//lots of backend logic
valid = true;
return "/agreementDetail.xhtml?faces-redirect=true";
}catch(Exception e){
valid = false;
return null;
}
}
基本上,这是我需要的行为:
用户输入一个 serviceId。如果此服务 ID 有效,它会将用户重定向到 agreementDetail.xhtml 页面。如果为 false,则用户将保留在 main.xhtml 页面中并呈现“服务 ID 无效...”消息。
这就是正在发生的事情:
如果用户输入了正确的服务 ID,一切正常。如果用户返回 main.xhtml 并输入了错误的服务 id,则错误会正确显示。但是现在,如果用户输入了正确的服务 id,则不会执行 build() 方法。(我已经通过记录确认了这一点)。
基本上,一旦用户输入了错误的值,除非用户注销并再次登录,否则 build() 方法将不会再次执行。显然,当 build() 发现错误并捕获异常时,事情就发生了。
有任何想法吗?