0

私は PrimeFaces 3.5 を使用していますが、部分的なページ レンダリングで問題が発生しました。Facelet ファイルからテンプレートの「動的」部分にコンテンツをロードする必要があります。

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:

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

をクリックすると<p:commandButton>content-2.xhtmlが開きます。ただし、これによりページ全体が更新されます。XML 応答には、次のような内容が含まれます。

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

action属性をメソッド式に変更すると:

<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ブロックは期待どおりに更新されます。XML 応答には、次のような内容が含まれます。

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

action="content-2?faces-redirect=false"ウェイがページ全体を更新するのはなぜですか?

私も試しまし<ui:composition>たが、この場合、これはテンプレートの「静的」部分をリロードします。いりません。

4

1 に答える 1

0

属性に非結果を指定して別のビューに移動した場合、これは完全に正常で予期される動作です。次に、JSF は のレンダリングで部分レンダリングを却下します。JSF/Facelets は、あなたが期待しているように、何らかの方法でツリー内の共通コンポーネントを自動的に保持しません。部分的なページのレンダリング中にコンポーネント ツリーを動的に変更する場合は、次のような動的なインクルードが必要です (は単なる整数です)。nullaction@all<p:outputPanel id="display" layout="block">section

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

または複数の条件付きでレンダリングされたセクション

<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 を参照しているかどうかに応じて、それぞれに長所と短所があります。つまり、JSTLの<ui:include>ようなビューのビルド時に実行されます。詳細については、JSF2 Facelets の JSTL も参照してください...意味がありますか?

の存在はfaces-redirect=false、すでにデフォルトであるため重要ではありません。である場合true、JavaScriptwindow.locationがターゲット URL で呼び出されます。

于 2013-04-11T17:33:53.223 に答える