【问题标题】:Reporting error in jsf using tag onerror in menuitem tag在 jsf 中使用 menuitem 标签中的标签 onerror 报告错误
【发布时间】:2015-06-28 05:33:51
【问题描述】:

我是 jsf 的新手,想在下面的 xhtml 代码中使用标签“onerror”在primefaces(使用jsf 2)中引发一个带有错误的对话框

<h:form>
<p:growl id="errorgrowl"  autoUpdate="true" life="5000" severity="error,fatal"/>
..
..
    <p:submenu label="${messages.mLinkView}">
        <p:menuitem value="${messages.mShowOnMap}" target="_blank" outcome="#{linkViewController.showLinkView(nobListController.csvParser,nobListController.allNobMan)}" update="errorgrowl"/>
        <p:menuitem value="${messages.mShowPhyLinksOnMap}" target="_blank" outcome="#{linkViewController.showPhyLinkView(nobListController.csvParserPhyLinks,nobListController.allNobMan)}" update="errorgrowl" />
    </p:submenu>

java: 捕获(异常 e) { log.error ("prepareNElistPhyLinks() 计算 MPLS-Xc 链接失败" + ((e instanceof GeneralException) ? ((GeneralException)e).reason : e.getMessage ())); e.printStackTrace(); FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage()); FacesContext.getCurrentInstance().addMessage(null, facesMsg); FacesContext.getCurrentInstance().validationFailed();
}

非常感谢

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    只需通过p:growl举报即可

    <h:form> 
       <p:growl id="errorgrowl"  autoUpdate="true" life="5000" severity="error,fatal"/>
     ...
    <h:form> 
    

    在 bean 中:

    try {
        ...
    }catch(Exception e) {
      FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, e.getMessage(), e.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, facesMsg);
        // FacesContext.getCurrentInstance().validationFailed(); may need this also
    }
    

    【讨论】:

    • 感谢您的意见。我按照您的建议进行了更改。但它不起作用。
      ....
    猜你喜欢
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多