有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用jGrowl创建JSF消息

我需要显示带有jGrowl的消息,如下所示:

enter image description here

我需要使用Map将消息存储到托管bean中。棘手的部分是,我想在插入消息后立即将其显示到Map中。我认为解决方案是从浏览器无限地向服务器进行Ajax调用。我如何在JSF中实现这一点


共 (1) 个答案

  1. # 1 楼答案

    如果你能使用素面,这真的很容易

    在xhtml中

    <p:panel header="Map">  
        <h:panelGrid columns="3">  
            <h:outputText value="Map Info: " />   
            <p:inputText value="#{myBean.key}" label="Name"/>  
            <p:inputText value="#{myBean.value}" label="Name"/> 
        </h:panelGrid>  
    
        <p:commandButton value="Save" actionListener="#{myBean.save}" update="growl"/>  
    </p:panel>  
    

    在爪哇

    公共类MyBean{

    private String key;  
    private String value;  
    
    public String getKey() {  
        return text;  
    }  
    public void setKey(String key) {  
        this.key = key;  
    }
    
    public String getValue() {  
        return value;  
    }  
    public void setValue(String value) {  
        this.value = value;  
    }   
    
    public void save(ActionEvent actionEvent) {  
        FacesContext context = FacesContext.getCurrentInstance();  
    
        context.addMessage(null, new FacesMessage("Successful", "Key : " + key + " Value : " + value));    
    }  
    

    }

    有关更多详细信息,请使用此链接http://www.primefaces.org/showcase-labs/ui/growl.jsf