JSF如何从bean获取方法?

JSF如何从bean获取方法?,jsf,liferay,Jsf,Liferay,我想使用h:commandLink发布到我的backingbean方法。之后,我想从bean方法打开站点中的另一个页面。如何做到这一点?使用h:commandLink绑定bean actionListener,并从操作重定向,如下所示: XHTML: <h:commandLink value="Redirect Link" actionListener="#{yourBean.redirectLinkAction}"> <f:param name="para

我想使用
h:commandLink
发布到我的backingbean方法。之后,我想从bean方法打开站点中的另一个页面。如何做到这一点?

使用h:commandLink绑定bean actionListener,并从操作重定向,如下所示:

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
    }
}

Bean:

<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
    }
}
public void showAddressBook(ActionEvent ae){
试一试{
外部上下文外部上下文=
FacesContext.getCurrentInstance().getExternalContext();
Map params=externalContext.getRequestParameterMap();
字符串param1=(字符串)params.get(“param1”);
/*对此处的参数执行必要的操作*/
String redirectURL=“您的URL”;
重定向(重定向URL);
}捕获(例外e){
//此处记录错误
}
}

如果您希望发送重定向(),则将
?faces redirect=true
附加到与您感兴趣的
相关联的操作方法的导航案例结果中。我的URL应为/users/view格式(一个友好的URL),但未找到:javax.servlet.ServletException:File”/users/view.jsp。我使用的是xhtml而不是jsp。如何重定向到友好的url?这可能是您的映射问题。试试/users/yourview.xhtml什么样的应用程序,你想实现它吗?在Liferay 6.1+JSF 2+Primefaces 5中,
java.io.IOException
在这种情况下完全不需要捕获。最好让它由action listener方法抛出-
抛出IOException
或者更好,只需将方法签名更改为具有返回类型的字符串,并让它返回适当的导航案例结果,并将
?faces redirect=true
附加到
action=“#{yourBean.redirectLinkAction}”