Java 在注销前咆哮
我已经建立了一个客户端,你可以登录,观察一些事情和注销。一切正常。如果你点击注销按钮,他将直接注销并将我发送回我的登录页面。这直接发生在单击注销按钮之后。所以我想在客户端将我发送回登录页面之前增加大约3秒的等待时间。另外,我想添加一个咆哮弹出消息,这是说:“你正在注销…”。 问题是,客户端在发送回我之前没有等待3秒钟,也没有显示对话框。他直接送我回去。如果我只想在单击时显示对话框,他做得很好,如果我只想在注销前等待3秒钟,他做得很好,他正在等待。但当我把这两件事(弹出和等待秒)结合起来时,他并没有这样做,而是直接把我送回Java 在注销前咆哮,java,html,primefaces,Java,Html,Primefaces,我已经建立了一个客户端,你可以登录,观察一些事情和注销。一切正常。如果你点击注销按钮,他将直接注销并将我发送回我的登录页面。这直接发生在单击注销按钮之后。所以我想在客户端将我发送回登录页面之前增加大约3秒的等待时间。另外,我想添加一个咆哮弹出消息,这是说:“你正在注销…”。 问题是,客户端在发送回我之前没有等待3秒钟,也没有显示对话框。他直接送我回去。如果我只想在单击时显示对话框,他做得很好,如果我只想在注销前等待3秒钟,他做得很好,他正在等待。但当我把这两件事(弹出和等待秒)结合起来时,他并没
public void logout() {
try {
Thread thread = new Thread();
try {
thread.sleep(3000);
ExternalContext ec = FacesContext.getCurrentInstance()
.getExternalContext();
ec.invalidateSession();
ec.redirect(ec.getRequestContextPath() + "/home.xhtml");
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void showLogoutMessage() {
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Logout",
"Sie werden abgemeldet!"));
logout();
}
<p:growl id="growl" showDetail="true" sticky="false" life="2000" autoUpdate="true" />
<p:commandButton value="#{navigationBean.abmelden}" ajax="false"
action="#{navigationBean.showLogoutMessage()}" update="growl" styleClass="menubutton"
style="position:relative;top:20px">
</p:commandButton>
public void注销(){
试一试{
线程=新线程();
试一试{
睡眠(3000);
ExternalContext ec=FacesContext.getCurrentInstance()
.getExternalContext();
ec.invalidateSession();
重定向(ec.getRequestContextPath()+“/home.xhtml”);
}捕捉(中断异常e){
e、 printStackTrace();
}
}捕获(IOE异常){
e、 printStackTrace();
}
}
public void showLogoutMessage(){
FacesContext context=FacesContext.getCurrentInstance();
addMessage(空,新面孔消息(“注销”),
“你是韦登·阿吉梅尔德特!”;
注销();
}
有谁能帮我或给我另一种解决方案的提示吗?您可以这样使用:
public void showLogoutMessage(){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Logout",
"Sie werden abgemeldet!"));}
public void logout() {
try {
Thread thread = new Thread();
try {
thread.sleep(3000);
ExternalContext ec = FacesContext.getCurrentInstance()
.getExternalContext();
ec.invalidateSession();
ec.redirect(ec.getRequestContextPath() + "/home.xhtml");
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();}
}
xhtml:
<p:growl id="growlmm" showDetail="true" sticky="false" life="2000" autoUpdate="true" />
<p:commandButton value="test" ajax="true"
actionListener="#{templateMB.mm()}" update="growlmm" styleClass="menubutton"
style="position:relative;top:20px" oncomplete="myLogout();">
</p:commandButton>
<p:remoteCommand id="rcom3" name="rclogout" process="@this" action="#{templateMB.goOut()}"/>
<script type="text/javascript">
function myLogout() {
setTimeout('rclogout();', 3000);
}
</script>
函数myLogout(){
setTimeout('rclogout();',3000);
}
感谢您的回复。咆哮消息弹出,但客户端未注销。。。脚本是否需要一些特殊的标记?将此代码复制并粘贴到xhtml中,请参见命令按钮上的oncomplete,以及showLogoutMessage方法中的Don't call logout方法。