0

我对 p:menuItem 有这个问题 - 使用 PF 3.3.1、PrettyFaces 3.3.3 和 JSF/Mojarra2.1。

所以我有一组 p:menuItems 需要从当前页面传递一个“ID”参数。但是,我不希望构建以下形式的 URL:/page/targetPage?id=id&faces-redirect=true。我想做的是,在页面操作处理程序上,重定向到有问题的 URL。但是,问题是生成的重定向将 windowId 附加到末尾,我无法访问 targetURL!

在我的小脸上:

<p:menuitem action="#{myActions.performAction}" ajax="false" value="navigateToThisAction"/>

在我的支持 bean 中:

public String performAction() {
    return navigate("pretty:myAction");
}

protected String navigate(String mappingId) {
    HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
    PrettyContext context = PrettyContext.getCurrentInstance(request);
    PrettyURLBuilder builder = new PrettyURLBuilder();

    UrlMapping mapping = context.getConfig().getMappingById(mappingId);
    String targetURL = builder.build(mapping, true, getId());

    try {
        FacesContext.getCurrentInstance().getExternalContext().redirect(targetURL);
    } catch (IOException ioe) {
        System.out.println("Error redirecting..." + ioe.getMessage());
    }
    return null;

}
4

2 回答 2

0

我发现问题是在重定向之前我在 URL 前面缺少 request.getContextPath() - 感谢所有回复!

于 2012-07-20T22:12:19.213 回答
0

如果 windowId=xxxxx 正在通过您的调用添加FacesContext.getCurrentInstance().getExternalContext().redirect(targetURL);,那么您可能需要检查您的框架以查看添加了什么。PrettyFaces 不会添加 windowId 参数,所以我猜它是其他东西,您正在使用的其他一些库,并且可能有一种方法可以在给定页面上手动禁用它。

于 2012-07-18T17:46:00.887 回答