programing

JSF, 구성 요소를 주기적으로 ajax로 새로 고침?

lovejava 2023. 10. 1. 19:00

JSF, 구성 요소를 주기적으로 ajax로 새로 고침?

저는 애플리케이션 JSF를 작업하고 있는데 주기적으로 ajax Like facebook 알림 존 동작으로 구성 요소를 새로 고치고 싶습니다.내가 어떻게 그럴 수 있을까?

Poll은 당신이 사용할 필요가 있는 것입니다.

Poll 구성 요소는 지정된 간격으로 ajax 호출을 합니다.

예를 들어 프라임페이스 여론조사

<h:form id="form">
    <h:outputText id="txt_count" value="#{counterBean.count}" />
    <p:poll interval="3" listener="#{counterBean.increment}" update="txt_count" />
</h:form>

프라임페이스 아약스 여론조사 공개 링크

순수한 JSF 접근 방식은 주기적으로 호출하는 js 타이머를 사용하는 것입니다.document.getElementById('someFormId:idOfButton').click();

잡동사니$("#someFormId\\:idOfButton").click();

버튼이 이렇게 보일 동안.

<h:commandButton id="idOfButton">
    <f:ajax render="txt_count"></f:ajax>
</h:commandButton>

이와 같은 것

setInterval(function(){$("idOfButton").click()},3000);

JavaScript 타이밍 이벤트 타이머에 대해 자세히 알아보기

RichFaces에는 여론조사 구성요소도 있습니다.여기 그들이 제공하는 좋은 예가 있습니다.

<a4j:region>
      <h:form>
            <a4j:poll id="poll" interval="1000" enabled="#{userBean.pollEnabled}" reRender="poll,grid"/>
      </h:form>
</a4j:region>

<h:form>
      <h:panelGrid columns="2" width="80%" id="grid">
           <h:panelGrid columns="1">
                <h:outputText value="Polling Inactive" rendered="#{not userBean.pollEnabled}" />
                <h:outputText value="Polling Active" rendered="#{userBean.pollEnabled}" />
                <a4j:commandButton style="width:120px" id="control" value="#{userBean.pollEnabled?'Stop':'Start'} Polling" reRender="poll, grid">  
                     <a4j:actionparam name="polling" value="#{!userBean.pollEnabled}" assignTo="#{userBean.pollEnabled}"/>
                </a4j:commandButton>
          </h:panelGrid>
          <h:outputText id="serverDate" style="font-size:16px" value="Server Date: #{userBean.date}"/>
    </h:panelGrid>
</h:form>

언급URL : https://stackoverflow.com/questions/11228198/jsf-refresh-periodically-a-component-with-ajax