Ok, with all the answers to this question I'm still not able to handle my problem. I have the following constellation:
In a JSF (1.1) webapp I have a request scoped bean bean
of class Bean
. When the user quickly clicks a commandButton
multiple times to redirect him to the insult.xhtml
page the doSomethingThatTakesALittleLongerAndShouldOnlyBeDoneOnce
method may get invoked multiple times (on Tomcat 6). How can I prevent this?
...
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>