2013-04-10 1 views
0

PrimeFaces 3.5를 사용 중이며 부분 페이지 렌더링에 문제가 있습니다. Facelet 파일의 내용을 템플릿의 "동적"부분에로드해야합니다. 얼굴 리디렉션을 통한 부분 페이지 렌더링 (PPR)

index.xhtml

:

<f:view> 
    <h:form id="form1"> 
     <p:outputPanel layout="block"> 
      <p:commandButton action="content-2?faces-redirect=false" update="display" /> 
     </p:outputPanel> 
     <p:outputPanel id="display" layout="block"> 
      content 1 
     </p:outputPanel> 
    </h:form> 
</f:view> 

content-2.xhtml : 나는 <p:commandButton> 클릭하면

<h:body> 
    content 2 loaded 
</h:body> 

, 다음 content-2.xhtml가 열립니다. 그러나 이것은 전체 페이지를 새로 고칩니다. XML 응답은 다음과 같이 포함되어 예상대로

<f:view> 
    <h:form id="form1"> 
     <p:outputPanel layout="block"> 
      <p:commandButton action="#{myBean.increment}" update="display" /> 
     </p:outputPanel> 
     <p:outputPanel id="display" layout="block"> 
      #{myBean.count} 
     </p:outputPanel> 
    </h:form> 
</f:view> 

그런 다음 display 블록 업데이트 :

<partial-response><changes><update id="javax.faces.ViewRoot"> 

나는 방법의 표현에 action 속성을 변경합니다. XML 응답은 다음과 같이 포함

<partial-response><changes><update id="form:display"> 

action="content-2?faces-redirect=false" 방법은 전체 페이지를 업데이트합니까?

나는 또한 <ui:composition>을 시도했지만,이 경우 템플릿의 "정적"부분을 다시로드합니다. 나는 그것을 원하지 않는다. 당신이 action 속성에 비 null 결과를 제공하여 다른보기로를 탐색 경우

+0

'# {myBean.method}'가'content-2.xhtml'을 반환한다는 것을 의미합니까? 'faces-redirect = false'가 이미 기본값입니다. 왜 당신이 이것을 명시 적으로 언급하고 있는지 이해할 수 없습니다. 'action = "content-2.xhtml"이 다르게 행동 함을 의미합니까? – BalusC

+0

아니요, 죄송합니다. # {myBean.method} (으)로 업데이트 된 부분을 업데이트했습니다. 메소드 본문은'count ++'처럼 보입니다. 그리고'action = "content-2.xhtml"'그것도 새로 고침'javax.faces.ViewRoot'을 시도하지만'action = "# {myBean.increment}"'refresh'display'. 나는'faces-redirect = false'가'true' 또는'false'를 할당해야한다고 생각했습니다. – Mrusful

답변

0

이 행동 완전히 정상적인 예상이다. 그러면 JSF는 부분 렌더링을 @all의 렌더링으로 덮어 씁니다. JSF/Facelets는 예상대로 자동으로 트리의 공통 구성 요소를 유지하지 않습니다. 이 부분 페이지 렌더링 중에 동적으로 변화 구성 요소 트리에하려는 경우이 중 하나를 동적 이런 식으로 뭔가를 (section 그냥 정수)

<ui:include src="section#{bean.section}.xhtml" /> 

또는 여러 조건 렌더링 부분

포함 <p:outputPanel id="display" layout="block"> 내부에, 당신은 필요
<ui:fragment rendered="#{bean.section == 1}"><ui:include src="section1.xhtml" /></ui:fragment> 
<ui:fragment rendered="#{bean.section == 2}"><ui:include src="section2.xhtml" /></ui:fragment> 
<ui:fragment rendered="#{bean.section == 3}"><ui:include src="section3.xhtml" /></ui:fragment> 
<ui:fragment rendered="#{bean.section == 4}"><ui:include src="section4.xhtml" /></ui:fragment> 

각각은 포함 파일에 양식/입력/명령 구성 요소 및/또는 참조 범위가 지정된 bean이 들어 있는지 여부에 따라 고유 한 장단점이 있습니다. <ui:include>은 JSTL과 같은 뷰 빌드 시간 동안 실행됩니다. 더 자세한 내용을 보시려면 JSTL in JSF2 Facelets... makes sense?

faces-redirect=false의 존재 여부는 이미 기본값이므로 중요하지 않습니다. true 인 경우 대상 URL에서 window.location JavaScript가 호출됩니다.

+0

고마워, 내가 지금 이해한다고 생각해.페이지의 모든 블록이 서버의 상태와 독립적으로 업데이트 될 수 있도록 어떻게 할 수 있을지 생각했습니다. – Mrusful

관련 문제