Javascript 从java文件中的函数弹出简单的文本消息警报

Javascript 从java文件中的函数弹出简单的文本消息警报,javascript,java,html,jsf,Javascript,Java,Html,Jsf,现在我有一个Java文件,它的函数是: public void asd() throws SQLException { try { getConnections(); } catch (Exception ex) { Logger.getLogger(PSTimer.class.getName()).log(Level.SEVERE, null, ex); } MongoCursor<Document> cursor

现在我有一个Java文件,它的函数是:

public void asd() throws SQLException {

    try {
        getConnections();
    } catch (Exception ex) {
        Logger.getLogger(PSTimer.class.getName()).log(Level.SEVERE, null, ex);
    }

    MongoCursor<Document> cursor = (MongoCursor<Document>) database.getCollection("Partidoscontagem").find().sort(new Document("data", -1)).limit(1).iterator();
    if (cursor != null && cursor.hasNext()){
            ...
            ...
            ...
    } else {
        /*This is where I want to include the message "No document found"*/
    }
public void asd()引发SQLException{
试一试{
getConnections();
}捕获(例外情况除外){
Logger.getLogger(PSTimer.class.getName()).log(Level.SEVERE,null,ex);
}
MongoCursor=(MongoCursor)database.getCollection(“Partidoscontagem”).find().sort(新文档(“数据”,-1)).limit(1.iterator();
if(cursor!=null&&cursor.hasNext()){
...
...
...
}否则{
/*这就是我想要包含消息“找不到文档”的地方*/
}
我的html文件中有一个p:commandButton,代码如下:

<p:commandButton  actionListener="#{bean.asd()}">

我想知道在单击p:commandButton之后,在html文件中弹出窗口的正确方法,该按钮包含函数生成的文本。

这对我来说很有用


public void asd()引发SQLException{
如果(foo){
//做事
}否则{
AddInfo消息(“呃,这很有趣。”);
}
}
专用void addInfo消息(字符串摘要){
FacesMessage=新的FacesMessage(FacesMessage.SEVERITY_信息,摘要,空);
FacesContext.getCurrentInstance().addMessage(空,消息);
}   

与其创建所有的“AddInfo消息”方法,不如更好地使用OmniFaces..并更好地搜索重复项…这可能是一个好主意,尽管我很少赞成在代码中添加库只是为了解决一个可能重复的问题