1

ナビゲーション ルールからリクエスト スコープの JSF 2 Bean に結果の値を取得したいと考えています。どうやってやるの?

たとえば、a を押して連絡先ページにたどり着いた場合、ナビゲーション メニューに関連付けられたバッキング Bean で<h:link outcome="contacts">結果を取得したいと考えています。"contacts"

顔-config.xml

<navigation-rule>
    ...
    <navigation-case>
        <from-outcome>contacts</from-outcome>
        <to-view-id>/pages/contacts.xhtml</to-view-id>
    </navigation-case>
    ...
</navigation-rule>
4

1 に答える 1

5

JSFでは、知る限り、ConfigurableNavigationHandlerその情報を持つのは だけです。ConfigurableNavigationHandlerそのため、宛先ページで使用するためにリクエスト パラメータに結果を格納するカスタムを作成します。

  1. カスタム ナビゲーション ハンドラ

    public class NavigationHandlerTest extends ConfigurableNavigationHandler {
    
    private NavigationHandlerTest concreteHandler;
    
       public NavigationHandlerTest(NavigationHandler concreteHandler) {
        this.concreteHandler = concreteHandler;
       }
    
    
    @Override
       public void handleNavigation(FacesContext context, String fromAction, String    outcome){
        //Grab a hold of the request parameter part and save the outcome in it for
        //later retrieval
         FacesContext context = FacesContext.getCurrentInstance();
         ExternalContext ctx = context.getExternalContext();
         ctx.getRequestMap().put("currentOutcome", outcome);
    
        //resume normal navigation
         concreteHandler.handleNavigation(context, fromAction, outcome);   
        }   
      } 
    
  2. faces-config.xmlでハンドラを構成します

      <application>
         <navigation-handler>com.foo.bar.NavigationHandlerTest</navigation-handler>
      </application>
    
  3. 目的の Bean で取得する

      @ManagedProperty(value="#{param.currentOutcome}")
      String outcome;
      //getter and setter
    
于 2013-06-05T04:11:26.563 に答える