Jsf 关闭primefaces对话框并重定向主页面
在按钮的提交处理程序中,我有时必须关闭我的Jsf 关闭primefaces对话框并重定向主页面,jsf,redirect,jsf-2,primefaces,Jsf,Redirect,Jsf 2,Primefaces,在按钮的提交处理程序中,我有时必须关闭我的p:dialog,并立即执行主页的重定向。我试过下面的代码 RequestContext.getCurrentInstance().closeDialog(id); FacesContext.getCurrentInstance().getExternalContext() .redirect("../quote/select.xhtml?prospectid=" + id); 这包含在submit()中,通过简单的命令按钮调用: &l
p:dialog
,并立即执行主页的重定向。我试过下面的代码
RequestContext.getCurrentInstance().closeDialog(id);
FacesContext.getCurrentInstance().getExternalContext()
.redirect("../quote/select.xhtml?prospectid=" + id);
这包含在submit()中,通过简单的命令按钮调用:
<p:commandButton value="#{msg.common_save}" action="#{bean.submit}" />
不幸的是,这会在对话框中重定向,并且不会关闭对话框本身。
只使用第一行确实会关闭我的对话框,但是当然,我仍然需要重定向我的页面
有什么方法可以实现我想要的吗?好的,如果我没弄错的话,你是在通过action属性调用你的bean。这不是惯常的做法。检查以下示例:
<p:dialog widgetVar="dlg" modal="true" resizable="false" header="Dialog">
<!-- Dialog controls here -->
<!-- ... -->
<h:panelGroup>
<p:commandButton value="Close and redirect" actionListener="#{bean.closeListener}" action="/main" />
<p:commandButton value="Just close" onclick="PF('dlg').hide()"/>
</h:panelGroup>
</p:dialog>
“actionListener”属性用于执行此事件背后的任何代码。
“action”属性用于设置对话框结果-可以是.xhtml页面名称(可以省略扩展名),也可以是EL表达式引用返回字符串的bean方法。
在上面的示例中,Redirection将转到位于WebContent根目录中的main.xhtml页面
通常,首先执行“actionListener”,然后对结果进行求值,并将jsf视图更改为求值页面。如果您仍在寻找答案,那么我认为我已经完成了您需要的相同操作。
对不起,格式不好
以下是editor.xhtml文件的代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:x="http://java.sun.com/jsf/composite">
<f:view>
<h:head>
<title>Editor and dialog!</title>
</h:head>
<h:body>
<h:panelGrid columns="1" cellpadding="5">
<p:commandButton value="Edit Content" type="button" onclick="dlg2.show();" style="color:green;font-size:10px;"/>
</h:panelGrid>
<p:dialog header="Modal Dialog" widgetVar="dlg2" modal="true" >
<h:outputText value="Edit Content here" style="color:green"/>
<h:form>
<p:growl id="message" showDetail="true" />
<p:editor value="#{editorBean.value}" widgetVar="editContent" ></p:editor>
<p:commandButton value="Publish" action="editor?faces-redirect=true" update="message" onclick="dlg2.hide();">
<p:confirmDialog header="Confirmation" message="Are you sure?" icon="ui-icon-alert" />
</p:commandButton>
</h:form>
</p:dialog>
<div >
<h:outputText value="#{editorBean.value}"></h:outputText>
</div>
</h:body>
</f:view>
</html>
您能显示xhtml代码吗?不清楚如何调用托管bean.Edited,不过没什么特别的,只是一个触发ajax提交的p:commandButton。请注意,我也尝试了h:commandButton,得到了相同的结果。如果仍要重定向,为什么要关心是否关闭了对话框?因为,在对话框打开的情况下重定向时,只会重定向对话框中显示的iframe。正如问题所述,这正是我不需要的。
package com.dev;
import javax.faces.bean.ManagedBean;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.primefaces.event.CloseEvent;
@ManagedBean(name="editorBean")
public class EditorBean {
private static String value;
//private static String outValue;
public EditorBean() {
}
public void addMessage(String summary, String detail) {
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail);
FacesContext.getCurrentInstance().addMessage(null, message);
}
public String getValue() {
System.out.println("getValue()"+value);
return value;
}
public void setValue(String value) {
System.out.println("setValue()"+value);
addMessage("System Error", value+"! Please try again later.");
this.value = value;
//getOutValue();
}
/*public String getOutValue() {
this.outValue = value;
System.out.println("getOutValue()"+outValue);
return outValue;
}*/
}