好的,有了这个问题的所有答案,我仍然无法处理我的问题。我有以下星座:
在 JSF (1.1) webapp 中,我有一个请求范围的 beanbean
类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();
}
侮辱.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>