1

在单个 xhtml 上,我有两个页面 (p:page)。每个页面都有一个表格,并且在每个表格中,都定义了一个咆哮。当我在第一页时,单击按钮时会显示咆哮声。但是,当我在第二页时,不显示咆哮。以下是可重现的示例代码。

我没有使用 update="@form" 的原因是覆盖面板中有另一个表单,通过 @(.errorHandlingPanel) 选择器,我应该能够轻松触发咆哮,而无需知道当前是哪个页面上。

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:pm="http://primefaces.org/mobile"
      xmlns:ui="http://java.sun.com/jsf/facelets">

<f:view renderKitId="PRIMEFACES_MOBILE"/>

<h:head>
</h:head>

<h:body>
    <pm:page id="first">
        <pm:header title="Page 1"></pm:header>
        <pm:content>
            <h:form id="form1">

                <ui:include src="error_handling.jspx"/>

                <p:commandButton id="btn1" value="Save" actionListener="#{growlViewDev.saveMessage}"
                                 update="@(.errorHandlingPanel)"
                                 icon="check"/>
            </h:form>
        </pm:content>
        <pm:footer>
             <p:tabMenu>
                 <p:menuitem value="Page 1"
                        outcome="pm:first?transition=slide"/>
                 <p:menuitem value="Page 2"
                        outcome="pm:second?transition=slide"/>
            </p:tabMenu>
         </pm:footer>
    </pm:page>

    <pm:page id="second">
        <pm:header title="Page 2"></pm:header>
        <pm:content>
            <h:form id="form2">
                <ui:include src="error_handling.jspx"/>

                <p:commandButton id="btn2" value="Save" actionListener="#{growlViewDev.saveMessage2}"
                                 update="@(.errorHandlingPanel)"
                                 icon="check"/>
            </h:form>
        </pm:content>
        <pm:footer>
             <p:tabMenu>
                 <p:menuitem value="Page 1"
                        outcome="pm:first?transition=slide"/>
                 <p:menuitem value="Page 2"
                        outcome="pm:second?transition=slide"/>
            </p:tabMenu>
         </pm:footer>
    </pm:page>
</h:body>
</html>

--error_handling.jspx

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
        >
  <ui:composition>
      <p:outputPanel styleClass="errorHandlingPanel">
          <p:growl showDetail="true" showSummary="true" escape="false" sticky="true" globalOnly="true"/>
      </p:outputPanel>
  </ui:composition>
</html>

-- 托管 bean

 @ManagedBean
 public class GrowlViewDev {

    public void saveMessage() {
      FacesContext context = FacesContext.getCurrentInstance();

      context.addMessage(null, new FacesMessage("Successful",  "Your message: Button 1") );
      context.addMessage(null, new FacesMessage("Second Message", "Additional Message Detail"));
    }

    public void saveMessage2() {
        FacesContext context = FacesContext.getCurrentInstance();

        context.addMessage(null, new FacesMessage("Successful",  "Your message: Button 2") );
        context.addMessage(null, new FacesMessage("Second Message", "Additional Message Detail"));
    }
}

用 5.1、5.2 和 5.3 测试

谢谢, ilhami visne

4

1 回答 1

0

不知何故,页面导航后似乎没有调用 show 方法。我发现的唯一解决方法是oncomplete使用以下方法在 ajax 组件属性中手动显示消息:

<p:growl id="growl" widgetVar="growlWidgetVar"/>

<p:commandButton outcome="pm:otherPage" update=":growl" oncomplete="showGrowl('growlWidgetVar');"/>

/* 
 * show current growl message again - PF-mobile bug on page navigation not showing it 
 * 
 * @param widgetVar PF widgetVar
 */
function showGrowl(widgetVar)
{
    PF(widgetVar).show(PF(widgetVar).cfg.msgs);
}

即使显示咆哮声,导航也经常发生。对于这种情况,请pageshow改为在处理程序中调用它:

$(document).on('pageshow', '#myPage', function(){
    showGrowl('growlWidgetVar');
});
于 2017-02-21T00:42:28.597 回答