在咆哮中使用 primefaces commandLink 显示模态对话框
Show a modal dialog using primefaces commandLink in a growl
我想将此命令 Link 放在我的视图消息中,以便它在咆哮中呈现,并且我可以在单击该命令时打开一个对话框 link。
<p:commandLink onclick="PF('dlg_new_user').show()" value="Click Here" />
<p:growl id="msgs" showDetail="true" sticky="true" globalOnly="true" escape="false" />
我的留言:
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Title" , message ));
我使用下面的解决方案让它工作,但是咆哮的内容是用转义 html 渲染的,它在几秒钟后渲染了 link。
String message = "User not found, <a href=\"#\" onclick=\"PF('dlg_new_user').show();\">Click Here</a> to create new user";
例如:
网页
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test my Growl Message</title>
<link type="text/css" rel="stylesheet"
href="#{facesContext.externalContext.requestContextPath}/resources/css/controlpanel.css " />
</h:head>
<h:body>
<h:form id="test" prependId="false">
<p:growl id="msgs" showDetail="true" sticky="true" globalOnly="true" escape="false" />
<p:outputLabel>
No user found!! <p:commandButton id="btn" value="Click Here" action="#{searchMB.searchSPU}" styleClass="botao_form" update=":test, :msgs, :dialog_user" /> to new User.
</p:outputLabel>
</h:form>
<p:dialog id="dialog_user" header="New User" widgetVar="dlg_new_user"
position="center" draggable="true" resizable="false"
closeOnEscape="true" appendTo="@(body)" modal="true">
<!-- Dialog content -->
</p:dialog>
</h:body>
</html>
MB:
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
@ManagedBean(name="searchMB")
@SessionScoped
public class TesteMB {
private static final String mainMessage = "Username not founded.";
private static final String link = "<a href=\"#\" onclick=\"PF('dlg_new_user').show();\">CLCK HERE</a> to create a new user.";
public String searchSPU(){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "No register founded" , mainMessage + "<br/>" + link ));
return null;
}
}
问题已解决,我使用了两个 growls,其中一个生成了错误的 html 代码。
我想将此命令 Link 放在我的视图消息中,以便它在咆哮中呈现,并且我可以在单击该命令时打开一个对话框 link。
<p:commandLink onclick="PF('dlg_new_user').show()" value="Click Here" />
<p:growl id="msgs" showDetail="true" sticky="true" globalOnly="true" escape="false" />
我的留言:
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Title" , message ));
我使用下面的解决方案让它工作,但是咆哮的内容是用转义 html 渲染的,它在几秒钟后渲染了 link。
String message = "User not found, <a href=\"#\" onclick=\"PF('dlg_new_user').show();\">Click Here</a> to create new user";
例如:
网页
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test my Growl Message</title>
<link type="text/css" rel="stylesheet"
href="#{facesContext.externalContext.requestContextPath}/resources/css/controlpanel.css " />
</h:head>
<h:body>
<h:form id="test" prependId="false">
<p:growl id="msgs" showDetail="true" sticky="true" globalOnly="true" escape="false" />
<p:outputLabel>
No user found!! <p:commandButton id="btn" value="Click Here" action="#{searchMB.searchSPU}" styleClass="botao_form" update=":test, :msgs, :dialog_user" /> to new User.
</p:outputLabel>
</h:form>
<p:dialog id="dialog_user" header="New User" widgetVar="dlg_new_user"
position="center" draggable="true" resizable="false"
closeOnEscape="true" appendTo="@(body)" modal="true">
<!-- Dialog content -->
</p:dialog>
</h:body>
</html>
MB:
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
@ManagedBean(name="searchMB")
@SessionScoped
public class TesteMB {
private static final String mainMessage = "Username not founded.";
private static final String link = "<a href=\"#\" onclick=\"PF('dlg_new_user').show();\">CLCK HERE</a> to create a new user.";
public String searchSPU(){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "No register founded" , mainMessage + "<br/>" + link ));
return null;
}
}
问题已解决,我使用了两个 growls,其中一个生成了错误的 html 代码。