2015-01-27 2 views
1

PrimeFaces 5.10, JSF 2 및 Wildfly를 사용하여 xhtml 페이지가 PF 폴링 구성 요소를 사용하여 @SessionScoped 빈의 단일 인스턴스와 상호 작용하도록하려고합니다. 폴링이 Bean 메소드를 호출 할 때마다 Bean의 새 인스턴스가 작성됩니다. @ViewScoped 및 @SessionScoped를 동작에 변경하지 않고 시도했습니다. 다른 유사한 질문을 발견했지만 구현할 수있는 솔루션으로는 보지 못했습니다.@SessionScoped bean

println은 메서드 호출 순서를 표시하는 신뢰할 수있는 방법이 아니라는 것을 알고 있습니다. 그러나 나는이 메서드를 호출하여 메서드를 호출하는 방법을 보여 주기만하고 init() 메서드가 계속 호출되는 것처럼 보입니다. 나는 @PostConstruct를 가지고 있기 때문에 새로운 인스턴스화가된다. 나는 "이"를 인쇄하고 심지어 인쇄 할 때마다 다른 해시를 보여주고 있습니다.

stopPolling 필드가 올바른 컨텍스트에서 false로 설정되지 않기 때문에 refreshTweets()에서 if 문을 통과하지 않습니다.

이전에이 문제가 발생하여 해결하기보다는 해결할 수있었습니다. 누군가 내가 뭘 잘못하고 있는지에 대한 아이디어가 있다면 알려주십시오.

<p:layoutUnit id="center" position="center" styleClass="dataBox"> 
    <h:form id="TwitterFeed"> 
     <p:panelGrid columns="2"> 
      <p:outputLabel value="Twitter topic to query: " /> 
      <p:inputText value="#{dataBean.tweetTopic}"/> 
      <p:outputLabel value="Number of Twitter Results: " /> 
      <p:inputText value="#{dataBean.tweetCount}" /> 
      <p:commandButton value="Submit" action="#{dataBean.toggleRenderTweets}" update="tweets"/> 
      <p:commandButton value="Polling" action="#{dataBean.togglePolling}" update="tweets"/>       
     </p:panelGrid> 
     <p:panel visible="#{dataBean.renderTweets}" id="tweets"> 
      <p:panelGrid columns="1"> 
       <p:dataTable id="twitterTable" value="#{dataBean.tweetList}" var="tweetStatus"> 
        <p:columns value="#{dataBean.tweetColumns}" var="column" columnIndexVar="colIndex"> 
         <f:facet name="header"> 
          <h:outputText value="#{column.header}"/> 
         </f:facet> 
         <h:outputText value="#{tweetStatus[column.property]}"/> 
        </p:columns> 
       </p:dataTable> 
       <p:poll interval="10" listener="#{dataBean.refreshTweets}" update="twitterTable" widgetVar="tweetPoll" id="tweetPoll" autoStart="true"/> 
      </p:panelGrid> 
     </p:panel> 
    </h:form>   
</p:layoutUnit> 

관련 콩 코드는 다음과 같습니다 :

import javax.enterprise.context.SessionScoped; 
import javax.faces.bean.ManagedBean; 
import javax.annotation.PostConstruct; 
import java.io.Serializable; 

@SessionScoped 
@ManagedBean 
public class DataBean implements Serializable { 

    private List<TwitterStatusModel> tweetList; 
    private boolean renderTweets; 
    private boolean stopPolling; 


    @PostConstruct 
    public void init() { 
     <<initialize fields>> 
     stopPolling = true; 
     System.out.println(this + " init()"); 
    } 

    private void getTweets() { 
     <<this method sets the List above tweetList>> 
    } 

    public void refreshTweets() { 
     if (!stopPolling) { 
      <<Method never passes the if statement because stopPolling is set to true in init() 
     } 

    public void togglePolling() { 
     stopPolling = !(stopPolling); 
     System.out.println(this + "Toggling polling - now " + stopPolling); 
    } 
+0

(게시하지 않았으므로) 반드시 SessionScoped 등을 올바르게 가져 왔습니까? @ManagedBean을 사용하면 javax.enterprise.context가 아닌 javax.faces.bean. * 또는 javax.faces.view가 아닌 ​​javax.faces.view – Kukeltje

+0

전화가 더 빨리 입력되거나 짧은 설명을 사용하도록 가르쳐주는 하하하가 필요합니다. – Kukeltje

+0

제안 된대로 가져 오기를 변경했으며 더 이상 빈을 여러 번 인스턴스화하지 않습니다. 나는 여전히 콩의 기능에 문제가있다.하지만 의자와 키보드 사이의 단락이 의심된다. ​​고맙다 !! 누군가가 답변을 제공하기 위해 최선의 답변으로 추천 할 수 있습니까? – Brooks

답변

2

당신은 당신이 필요 @ManagedBean과 함께 @SessionScoped 등 의 정확한 수입을 사용해야 아래

는 관련 XHTML 코드 javax.enterprise.context 또는 javax.faces.view가 아닌 ​​javax.faces.bean. *

도 참조하십시오. Why are there different bean management annotations