JSF如何从bean方法中获取GET?

JSF how to do a GET from bean method?

我想对我的支持 bean 方法使用 h:commandLink 到 post。之后我想从 bean 方法打开站点内的另一个页面。怎么做?

用 h:commandLink 绑定一个 bean actionListener 并从 action 重定向如下:

XHTML:

<h:commandLink  value="Redirect Link" 
    actionListener="#{yourBean.redirectLinkAction}">
    <f:param name="param1" value="param1Value" />
</h:commandLink>

豆豆:

public void showAddressBook(ActionEvent ae) {
    try {
        ExternalContext externalContext = 
            FacesContext.getCurrentInstance().getExternalContext();
        Map<String, String> params = externalContext.getRequestParameterMap();
        String param1 = (String) params.get("param1");

        /* Do necessary action with parameter(s) here */

        String redirectURL = "Your URL";            
        externalContext.redirect(redirectURL);

    } catch (Exception e) {
        // log error here
    }
}