1

我想从导航规则中获取结果值到请求范围的 JSF 2 bean 中。我怎样才能做到这一点?

例如,当我按下 a<h:link outcome="contacts">并最终进入联系人页面时,我想"contacts"在与导航菜单关联的支持 bean 中获得结果。

面孔-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、AFAIK 中,只有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 回答