4

I have a proper newbie SEAM question, I want to redirect the user to a different page from a backing bean

I know in most cases you should use pages.xml however there could be a number of different pages depending on the bean logic so it seems like it should be a lot easier to do from the bean.

I cant see any examples of people doing this so Im guessing there is a reason why, Maybe something like this would work??...

ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
((HttpServletRequest) ec.redirect("http://example.com/");

1 Answer 1

5

You can use the Redirect component:

@Name("yourBean")
public class YourBean {

  @In
  Redirect redirect;

  public void yourMethod() {
     redirect.setViewId("/someView.xhtml");
     redirect.setParameter("someParam", "someValue");
     redirect.execute();
  }
}

Or going with FacesManager:

FacesManager.instance().redirect("/someView.xhtml", paramMap,
  conversationPropagationEnabled, includePageParams);

These only work for other JSF views (ie .xhtml). If you just want an arbitrary URL, you can use the FacesContext as you mentioned in your question.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.