0

I have this issue with p:menuItem - using PF 3.3.1, PrettyFaces 3.3.3 and JSF/Mojarra2.1.

So I have a set of p:menuItems that need to pass through an "ID" parameter from the current page. However, I do not wish to build a URL of the form: /page/targetPage?id=id&faces-redirect=true. What I would like to do is, on the page action handler, redirect to the URL in question. However, the problem is that the resulting redirect attaches a windowId to the end and I cannot access the targetURL!

in my facelet:

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

In my backing 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;

}
Nena
  • 681
  • 1
  • 10
  • 27
  • PS - the result in the browser is something like: http://localhost:8080/page/myAction/10651?windowId=bce because of the window id at the end (i think) I am getting a 404 not found error.... – Nena Jul 18 '12 at 00:08
  • If you erase this `windowId=` manually in your browser do you still get the 404 error? – Luiggi Mendoza Jul 18 '12 at 00:14
  • 1
    while debugging have you checked the `targetURL` value before it is send to the redirect? – Luiggi Mendoza Jul 18 '12 at 00:21

2 Answers2

0

If the windowId=xxxxx is being added by your call to FacesContext.getCurrentInstance().getExternalContext().redirect(targetURL);, then you probably want to check your frameworks to see what is adding that. PrettyFaces will not add a windowId parameter, so I'm guessing it is something else, some other library you are using, and there may be a way to disable that manually on a given page.

Lincoln
  • 3,151
  • 17
  • 22
0

I discovered that the problem was that I was missing request.getContextPath() in front of the URL before redirecting - thanks for all the responses!

Nena
  • 681
  • 1
  • 10
  • 27