2012-09-04 3 views
0

메서드 호출을 통해 Primafaces 출력 레이블을 채우는 것에 대한 질문이 있습니다. 이 방법에는 매개 변수가 필요했습니다.Primefaces OutputLabel을 매개 변수로 채우기

내 백업의 콩에서
<p:dataTable id="answerToQuestionDialogTable" var="answer" value="#{allQuestionBean.answers}"> 
    <p:column headerText="Counts For this Answer"> 
     <p:outputLabel value="#{allQuestionBean.votingCounter}"> 
      <f:param name="id" value="#{answer.answerId}"/> 
     </p:outputLabel> 
    </p:column> 
</p:dataTable> 

내가 따라 게터와 정수 필드 명 "votingCounter"이 :

레이블은 다음과 같다 내가 사이트를로드하려고하면

public int getVotingCounter() { 
     Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); 
     int answerID = Integer.parseInt(params.get("id")); 

     return answeredDAO.getCountForAnswer(answerID); 
    } 

를 내가 내 AppServer (Tomcat 6)에서 LogOutput을 얻으십시오.

04.09.2012 04:30:47 com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback visit 
SCHWERWIEGEND: javax.el.ELException: /pages/allQuestion.xhtml @69,81 value="#{allQuestionBean.votingCounter}": Error reading 'votingCounter' on type bean.view.AllQuestionBean 

왜이 원인지 설명 할 수있는 사람이 있습니까? t 작업과 나에게 내가 텍스트에 레이블을 채우는 방법을 호출하는 방법을 해결책을 줄 수 있습니까?

답변

2

에 대한 세터 것으로 추정 모든

<p:outputLabel value="#{AllQuestionBean.countForAnserMap[answer.answerId]}"> 
+0

안녕 다니엘, 들으. 당신의 팁으로 나는 그것을 얻었습니다. 혼란스럽게 생각하는 사람이 왼쪽. 나는 Primefaces에서 출력 레이블을 가지고 시험해 보았고 항상 Nullpointer를 얻었다. 그런 다음 JSFCore의 Label과 동일한 코드가 모두 올바르게 작동합니다. – Chris

-1

다음과 같이하십시오, 당신은 어쨌든 모든 대답에 대한 모든 카운트 답변을 가지고 가고 있기 때문에, 당신은 왜지도를 작성하고 그것을 채울 수없는 게터 가지고 votingCounter

<p:dataTable id="answerToQuestionDialogTable" var="answer" value="#{AllQuestionBean.answers}"> 
    <p:column headerText="Counts For this Answer"> 
     <p:outputLabel value="#{AllQuestionBean.votingCounter}"> 
      <f:param name="id" value="#{answer.answerId}"/> 
     </p:outputLabel> 
    </p:column> 
</p:dataTable> 
1

처음처럼 @PostConstruct하고 그것에게 간단한 방법을 액세스, 무엇인가, 당신은 당신의 구체적인 문제의 근본 원인에 대해 배울 스택 추적의 근본 원인을 읽어야합니다. 스택 추적의 근본 원인은 스택 추적의 맨 아래 부분입니다.

특정 경우에 Integer.parseInt(params.get("id"))을 시도하는 행을 가리키는 일반 문자 NullPointerException 일 가능성이 큽니다. 예외의 근본 원인은 구체적인 문제에 대해 훨씬 더 많은 것을 말해줍니다. params.get("id")null으로 돌아 왔다고하는 것은 기본적으로 <f:param>이 작동하지 않는다는 것을 의미합니다.

실제로 이것은 <f:param>의 목적이 아닙니다. getRequestParameterMap()은 실제 매개 변수가 인 URL을 가리키는 링크/버튼을 생성하지 않는 임의의 구성 요소에 포함 된 <f:param> 값이 아닌 실제 HTTP 요청 매개 변수를 반환합니다. 요청 (및 현재 요청!).

당신은 다니엘에 의해 제안 대신 솔루션을 구현해야한다, 또는 Answer 클래스에 votingCounter를 이동하거나 다음과 같은 다른 방법을 구현하기 : 당신의 응답에 대한

public int getVotingCounter() { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    Integer answerID = context.getApplication().evaluateExpressionGet(context, "#{answer.answerId}", Integer.class); 
    return answeredDAO.getCountForAnswer(answerID); 
} 
+0

안녕하세요 BalusC,이 질문에 대한 자세한 답변은 thx입니다. – Chris