2013-07-01 3 views
0

JSF 테스트 응용 프로그램 및 PrimeFaces 구성 요소에 문제가있어 오류를 찾을 수 없습니다. 관리 빈에서 리디렉션이 작동하지 않습니다.

나는에 의해 정의 된 템플릿 파일 (layoutTempl.xhtml)로 시작 :

.... 
<body> 
    <ui:composition template="./layoutTempl.xhtml"> 
     <ui:define name="menubar"> 
      MenuBar 
     </ui:define> 
     <ui:define name="tree"> 
      Project Tree 
     </ui:define> 
     <ui:define name="main"> 
      <ui:include src="index.xhtml"/> 
     </ui:define> 
     <ui:define name="footer"> 
      Footer 
     </ui:define> 
    </ui:composition> 
</body> 
.... 

과 (abcContent :

.... 
<h:body> 
    <p:layout fullPage="true" > 
     <p:layoutUnit position="north" size="95" > 
      <ui:insert name="menubar" > 
       MenuBar 
      </ui:insert>   
     </p:layoutUnit>   
     <p:layoutUnit position="west" resizable="false" size="250"> 
      <ui:insert name="tree" > 
       ProjectTree 
      </ui:insert>    
     </p:layoutUnit> 
     <p:layoutUnit position="center"> 
      <ui:insert name="main" > 
       MainContent 
      </ui:insert>   
     </p:layoutUnit> 
     <p:layoutUnit position="south" size="45"> 
      <ui:insert name="footer" > 
       Footer 
      </ui:insert> 
     </p:layoutUnit> 
    </p:layout>  
</h:body> 
.... 

이 템플릿은 두 페이지 (indexContent.xhtml)에 사용됩니다. XHTML) : 포함 index.xhtml

.... 
<body> 
    <ui:composition template="./layoutTempl.xhtml"> 
     <ui:define name="menubar"> 
      MenuBar 
     </ui:define> 
     <ui:define name="tree"> 
      Project Tree 
     </ui:define> 
     <ui:define name="main"> 
      <ui:include src="abc.xhtml"/> 
     </ui:define> 
     <ui:define name="footer"> 
      Footer 
     </ui:define> 
    </ui:composition>  
</body> 
.... 

포함 된 파일 :

.... 
<h:body> 
    <ui:composition > 
    Hello from BareTest 
    <br /><br /> 
    <h:form id="myform"> 
     <p:selectOneMenu id="scroll2" 
         value="#{listTestBean.selectedMyObject}" > 
      <f:selectItems value="#{listTestBean.myObjects}"/> 
      <p:ajax event="change" listener="#{listTestBean.valueChanged}"/> 
     </p:selectOneMenu> 
     <br/><br/> 
    </h:form> 
    </ui:composition> 
</h:body> 
.... 

는 abc.xhtml을 포함하면서 :

.... 
<h:body> 
    <h2>We got at abc page!</h2> 
    <br /><br /> 
    <h:form id="abcForm"> 
     <p>#{listTestBean.selectedMyObject}</p> 
     <p:commandLink id="Ajax" ajax="true" action="indexContent?faces-redirect=false"> 
      <h:outputText value="Main page (link)" /> 
     </p:commandLink> 
    </h:form> 
</h:body> 
.... 

요청 listTestBean 게터와 세터의 valueChanged 방법 및 수단을 포함 범위를 관리 빈. 의 valueChanged 방법은 보유 : 기본적 abcContent 페이지로 리디렉션이다

.... 
try { 
     FacesContext.getCurrentInstance().getExternalContext().redirect("abcContent.xhtml"); 
} catch (IOException ioe) { 
    System.err.println("listTestBean.valueChanged: IOException"); 
} 
.... 

한다.

그러나 selectItem 구성 요소에서 항목을 선택하면 abcContent.xhtml 페이지가 지정된 layoutTempl과 함께 렌더링되지 않습니까?

나는 전혀 이해하지 못한다. 미안하다! 그것은 아마 사소한 것이지만 그것을 해결할 수 없다!

안부

+0

페이지가 템플릿없이 렌더링되거나 전혀 렌더링되지 않는다고 말하는가? 또한 web.xml의 url 패턴은 무엇입니까? – zulq

+0

템플릿없이 렌더링됩니다! URL 패턴은 '/faces/*'처럼 보입니다. –

+0

페이지에 템플릿이 표시되지 않을 수 있습니다. 경로를 확인하고 페이지를 직접로드하고 확인하십시오. – zulq

답변

0

는 리디렉션에 대한 아약스가 필요하지 않습니다

<p:commandLink ajax="false" action="indexContent?faces-redirect=false"> 

을 시도합니다.

+0

어느 쪽도 도움이되지 않습니다! –

+0

[JSF PrimeFaces p : commandLink가 새 페이지로 리디렉션되지 않습니까?] (http://stackoverflow.com/questions/4900531/jsf-primefaces-pcommandlink-wont-redirect-to-new-page) – Przemek

0

template="./layoutTempl.xhtml"이 아닌 템플릿의 전체 상대 URL을 입력하십시오. 이것이 의미하는 바는 현재 디렉토리에서 템플릿을로드하는 것입니다. abcContent.xhtml에서

http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/

+0

모든 파일이 같은 디렉토리에 있으며, ./을 제거해도 도움이되지 않습니다. 죄송합니다! –

+0

빈에서 .xthml을 제거하고 페이지 이름 만 남겨 둘 수 있습니까? – zulq

+0

시도했지만 HTTP 404 오류가 발생했습니다 (자원을 찾을 수 없습니다!)! –

0

당신은

<ui:define name="main"> 
    <ui:include src="abc.xhtml"/> 
</ui:define> 

하지만 abc.xhtml

다음과 같이 정의된다 템플릿 페이지가 같은 디렉토리에있는 경우 바로 ./ 확인을 제거하는 템플릿 이름을 넣어 밖으로이 튜토리얼 템플릿
<h:body> 
    <h2>We got at abc page!</h2> 
    <br /><br /> 
    <h:form id="abcForm"> 
    ... 
    </h:form> 
</h:body> 

<ui:composition>. XHTML을 사용하고 있습니다. 잘못된 마크 업을 제공하면 JSF가 올바르게 해석되지 않습니다. IDE를 사용하는 경우 ui:include을 사용할 때 경고 메시지가 표시되지 않습니다. 브라우저를 열고 abcContent.xhtml에서 소스 코드보기를 클릭하면 직접 확인할 수 있습니다. 페이지의 일부분에 여전히 JSF 코드 (예 : h:body)가 포함되어 있음을 알 수 있습니다. abc.xhtml을 수정하고 다시 시도하십시오.

<h:body> 
    <ui:composition> 
     <h2>We got at abc page!</h2> 
     <br /><br /> 
     <h:form id="abcForm"> 
     ... 
     </h:form> 
    </ui:composition> 
</h:body> 
0

이 늦은 반응이지만 파일 경로

"abcContent.xhtml"

대신

때 내 경험에서, 그렇게는 "/ abcContent.xhtml에 직면"

브라우저의 검색 주소창에서 테스트 해 볼 수도 있습니다.

또한 파일이 "얼굴"이라는 폴더에 있음을 의미하지 않습니다. web.xml에 지정된 URL 패턴 일뿐입니다.

관련 문제