【问题标题】:Multiple dialogs with ajaxExceptionHandler on the same page同一页面上带有 ajaxExceptionHandler 的多个对话框
【发布时间】:2015-01-23 11:58:56
【问题描述】:

我有一个 xhtml 页面,其中声明了几个对话框

<ui:include src="/pages/dialogs/dialog1.xhtml"></ui:include>
<ui:include src="/pages/dialogs/dialog2.xhtml"></ui:include>
...

对话框是dynamic="true",每个对话框都有ajaxExceptionHandler

    <p:ajaxExceptionHandler update="exceptionDialog" onexception="PF('exceptionDialog').show();" /> 
<p:dialog widgetVar="exceptionDialog" id="exceptionDialog">...</p:dialog>

当某些对话框打开并在某些操作后发生异常时,什么也没有发生。 ExceptionDialog 未显示。

【问题讨论】:

    标签: primefaces exception-handling dialog


    【解决方案1】:

    问题是对话框后创建的&lt;p:ajaxExceptionHandler&gt; 包含在页面中&lt;ui:include&gt; 为时过早。您需要在对话框出现时创建它,因此您需要在托管 bean 中动态地创建它。 在每个对话框中执行此操作

    删除&lt;p:ajaxExceptionHandler&gt; 标签。 并添加 ...

    <h:panelGroup id="ajaxExceptionHandlerPlaceholder">
    </h:panelGroup>
    
    <p:outputLabel id="exceptionMessage" value="#{pfExceptionHandler.message}" style="color: red" />
    
    <script>
         createAjaxExceptionHandlerCommand();
    </script>
    </p:dialog>
    

    在托管 bean 中添加此方法

       public void createAjaxExceptionHandler() {
            AjaxExceptionHandler aeh = new AjaxExceptionHandler();
            aeh.setType( null );
            aeh.setUpdate( "exceptionMessage" );
    
            FacesContext context = FacesContext.getCurrentInstance();
            UIViewRoot root = context.getViewRoot();
            final UIComponent[] found = new UIComponent[1];
            root.visitTree( new FullVisitContext( context ), new VisitCallback() {
                @Override
                public VisitResult visit( VisitContext context, UIComponent component ) {
                    if ( component.getId().equals( "ajaxExceptionHandlerPlaceholder" ) ) {
                        found[0] = component;
                        return VisitResult.COMPLETE;
                    }
                    return VisitResult.ACCEPT;
                }
            } );
    
            found[0].getChildren().add( aeh );
        }
    

    【讨论】:

      猜你喜欢
      • 2021-09-04
      • 1970-01-01
      • 2014-02-15
      • 2014-06-19
      • 1970-01-01
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多