Navigate to other view passing a parameter

后端 未结 1 2028
无人及你
无人及你 2020-12-18 11:35

My current environment is JRE 1.7, JSF 2.2, Eclipse Luna. In a certain page (entity_index.xhtml) of my application I have the following (PrimeFaces) button:

1条回答
  •  一整个雨季
    2020-12-18 12:15

    p:commandButton performs a POST request. You want simply to GET a view with your entity detail, not to POST the server, so you need a h:link:

    
        
    
    

    Then, the f:viewParam in the destination page will be able to process the url parameter:

    
        
        
    
    

    Use a f:viewAction to initialize your entity instead of doing it in a getter, which is discouraged:

    public void init(){
        entity = entityById(id);
    }
    

    See also:

    • Choosing how to pass parameters to a target bean/page using JSF
    • When to use f:viewAction / preRenderView versus PostConstruct?

    0 讨论(0)
提交回复
热议问题