使用menuitem标记中的tag onerror报告jsf中的错误

时间:2015-04-21 07:33:04

标签: jsf-2 primefaces

我是jsf的新手,想要使用标签" onerror"在primefaces(使用jsf 2)中引发一个带有Error的对话框。在以下xhtml代码中

<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:             catch(例外e)             {                 log.error(&#34; prepareNElistPhyLinks()无法计算MPLS-Xc链接&#34; +                         ((e例如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();
            }

非常感谢

1 个答案:

答案 0 :(得分:0)

只需通过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
}