【问题标题】:primefaces 5.1 start ajaxStatus during preRenderViewprimefaces 5.1 在 preRenderView 期间启动 ajaxStatus
【发布时间】:2016-09-21 17:52:42
【问题描述】:

在 primefaces 中是否可以从支持 bean 的方法启动“ajax 状态”?我有以下看法

    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="/pages/templates/template.xhtml">
    <ui:define name="metadata">
    <f:event type="preRenderView" listener="#{preloadBean.init}" />
    </ui:define>    
    <ui:define name="content"> 
    <h:form id="form" >
    <p:growl id="growl" />
    <p:commandButton id="btn" value="Trigger ajaxStatus" actionListener="#{preloadBean.buttonAction}" /> 
    <f:facet name="start">
        <p:graphicImage name="images/ajaxloadingbar.gif" />
    </f:facet> 
    <f:facet name="complete">
         <h:panelGrid columns="4">
            <p:outputLabel value="#{preloadBean.nomeCognomeVis} - #{preloadBean.poloVis}" style="font-weight:bold" />
            <h:outputText value="Aggiornamento delle: #{preloadBean.ultimoAggiornamento}"></h:outputText>
            <p:commandButton actionListener="#{preloadBean.buttonAction}" id="aggiornaDati" update="growl" value="Aggiorna Dati" title="Aggiorna Dati" styleClass="ui-priority-primary" />
            <p:commandButton actionListener="#{preloadBean.buttonAction}" id="impersonifica" update="growl" value="Ut.P" title="Inpresonifica utente" styleClass="ui-priority-primary" />
        </h:panelGrid>  
    <p:dataTable var="record" value="#{preloadBean.records}" paginator="false" id="mainTable">        
        <p:column headerText="Polo" sortBy="#{record.polo}" filterBy="#{record.polo}" filterStyle="display:none">
            <h:outputText value="#{record.polo}" />
        </p:column>
        <p:column headerText="Operatore" sortBy="#{record.operatore}" filterBy="#{record.operatore}" filterStyle="display:none">
            <h:outputText value="#{record.operatore}" />
        </p:column>
        <p:column headerText="Aperti" sortBy="#{record.totaleAperti}" filterBy="#{record.totaleAperti}" filterStyle="display:none">
            <h:outputText value="#{record.totaleAperti}" />
        </p:column>      
    </p:dataTable>
    </f:facet>
</p:ajaxStatus>
    <p:ajaxStatus onstart="PF('statusDialog').show()" onsuccess="PF('statusDialog').hide()" />  
    <p:dialog widgetVar="statusDialog" modal="true" draggable="false" closable="false" resizable="false" showHeader="false">
    <p:graphicImage name="images/ajaxloadingbar.gif" />
</p:dialog>   
    </h:form>      
    </ui:define>
</ui:composition>

仅当我单击“btn”命令按钮时才有效。 我想在页面刷新或第一次访问时加载 ajax 状态。

【问题讨论】:

    标签: spring jsf jsf-2 primefaces


    【解决方案1】:

    这是一个在 HTML 的页脚中添加的示例:

    <p:ajaxStatus onstart="PF('statusDialog').show();" 
                  oncomplete="PF('statusDialog').hide();"
                  onerror="alert('Error msg. Please try again!');" />
    
    <p:dialog widgetVar="statusDialog" modal="true">
        <h:form prependId="false">
            <p:outputLabel value="Processing..." style="display: block; margin: 10px;" />
            <p:graphicImage library="images/icones" name="glow-ring.gif" />
            <p:outputLabel value="Wait!" style="display: block; margin: 10px;" />
        </h:form>
    </p:dialog>
    

    对话框仅在您调用 ajax 请求时启动。

    如果您只想在启动时显示对话框,而无需任何 ajax 请求,您可以使用:

    <p:remoteCommand name="onload" autoRun="true" process="@this" immediate="true"
                     onstart="PF('statusDialog').show();" 
                     oncomplete="PF('statusDialog').hide();" />
    

    【讨论】:

    • 问题是一个远程命令监听器被调用了两次!
    • Andrea,删除 name="onload"(或重命名)将解决这个问题,但我现在不记得这是最好的方法。因此,如果不能按预期工作 也许 set autoRun="false" 可以解决。您需要选择一个解决方案,因为在页面加载时启动 ajax 状态需要这些命令之一。
    • Sono molto felice di averti aiutato。 Grande Abbraccio dal Brasile!
    猜你喜欢
    • 2013-02-12
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 2015-12-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多