primefaces 5.1在preRenderView期间启动ajaxStatus

时间:2016-05-24 13:20:51

标签: spring jsf jsf-2 primefaces

在primefaces中的

可以开始" ajax status"从一个支持bean的方法?我有以下观点

    <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>

这项工作只有在我点击&#34; btn&#34;命令按钮。 我想在页面刷新时或第一次访问时加载ajax状态。

1 个答案:

答案 0 :(得分: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();" />