0

このビューがこの変数を使用するよりも、ビューが表示される前に使用するスコープのセッションに変数を適用したいと思います。

リンクは次のとおりです。

<h:link value="#{msg.persondeactivate}" outcome="persondeactivate" />

ここにfaces-config.xmlがあります

<navigation-rule>
    <navigation-case>
        <from-outcome>persondeactivate</from-outcome>
        <to-view-id>/deactivatePerson.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

ビュー (deactivatePerson.xhtml) は次のとおりです。

...<h:outputText value="#{msg.personIsDeactivate}" rendered="#{controller.personDeactivated}" style="color:green" />... <h:commandButton action="#{controller.deaktivieren}" value="#{msg.deactivate}"></h:commandButton>...

マネージドBeanは次のとおりです。

@ManagedBean @SessionScoped public class Controller { ... private boolean personDeactivated = false; public String deaktivieren(){ personDeactivated = false;
    // Deactivate process personDeactivated = true; return "persondeactivate";} ... }

ビュー (deactivatePerson.xhtml) が 2 回目に呼び出される前に、変数personDeactivatedをfalseに設定する必要があります。

それは動作しません。

誰かが何が悪いのか教えてもらえますか?

前もって感謝します。

4

1 に答える 1

0

<f:event type="preRenderView">ビューがレンダリングされる前に、バッキング Bean リスナー メソッドを呼び出すために使用できます。

<f:event type="preRenderView" listener="#{controller.onPreRenderView}" />

public void onPreRenderView() {
    if (!FacesContext.getCurrentInstance().isPostback()) {
        // Do your job here when the view is been freshly requested by GET.
    }
    else {
        // Do your job here when a POST request is been performed by command link/button.
    }
}

具体Controller的な問題とは関係ありませんが、実際には間違った範囲にあるという印象があります。はるかに優れた解決策は、@ViewScoped代わりにそれを作成することです。このようにして、Bean インスタンスはすべての新しい GET 要求で新しく作成され、まったく同じビューに POSTback している限り存続します (したがって、複数のブラウザー タブで同じページを開いているときに、矛盾や非直感的な動作に遭遇することはありません)まったく同じセッション スコープ Bean を共有する同じセッション内の /windows!)。適切な Bean スコープを選択する方法も参照してください。

于 2012-04-04T16:26:05.283 に答える