好的,所有的答案this question我仍然无法处理我的问题。 我有以下星座:如何防止在JSF应用程序中多次调用请求作用域bean方法?
在JSF(1.1)的web应用我有一个请求范围Bean
类的bean bean
。当用户多次点击commandButton
将他重定向到insult.xhtml
页面时,可能会多次调用doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce
方法(在Tomcat 6上)。我怎样才能防止这一点?
...
public Bean() {
HttpSession session = ((HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(false));
if(session != null && session.getAttribute("done") != null) {
doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce();
session.setAttribute("done", "done");
}
}
public void doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce() {
this.bossInsult = generateBossInsult();
}
insult.xhtml:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core">
<html>
<body>
#{bean.bossInsult}
</body>
</html>
</ui:composition>
这会工作,不幸的是,真实的情况是从我的例子有点不同。重定向发生在我无法控制的第三方页面上。 – ceggers 2010-10-14 10:13:33