在growl中使用primefaces commandLink显示模态对话框

时间:2016-02-25 13:22:17

标签: jsf primefaces modal-dialog commandlink growl

我想在我的查看消息上放置此命令链接,以便在咆哮上呈现,我可以在单击该链接时打开一个对话框。

<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渲染了growl的内容,并在几秒钟后呈现链接。

String message = "User not found, <a href=\"#\" onclick=\"PF('dlg_new_user').show();\">Click Here</a> to create new user";

http://imageshack.com/a/img921/9870/gsVHpS.png

例如:

网页

    <?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;

    }
}

1 个答案:

答案 0 :(得分:0)

问题解决了,我使用了两个咆哮,其中一个生成了错误的HTML代码。