0

i use Jsf 1.2 and have navigation rule with redirect, my question is how to add request parameters to view redirected

jrey
  • 2,163
  • 1
  • 32
  • 48
  • 1
    This looks like useful : http://stackoverflow.com/questions/3605238/how-do-you-pass-view-parameters-when-navigating-from-an-action-in-jsf2 – Omar Oct 25 '13 at 02:20
  • 2
    @Omar that works since JSF 2. OP's question is for JSF 1.2. – Luiggi Mendoza Oct 25 '13 at 05:19
  • Thanks, i see the solucion in JSF 2, but i dont know if exists a similar feature to JSSF 1.2 – jrey Oct 25 '13 at 11:03

1 Answers1

1

This isn't possible using navigation rules in JSF 1.x. Use ExternalContext#redirect() instead.

public void action() throws IOException {
    // ...

    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
    String url = ec.getRequestContextPath() + "/page.jsf?someparam=" + URLEncoder.encode(someparam, "UTF-8");
    ec.redirect(url);
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Instead of appending a new param as string to url, can I add query param key & value programatically through API? – user2918640 Mar 09 '16 at 12:23
  • 1
    @user2918640: You can. JSF only doesn't offer a public URL builder API. JSF utility library OmniFaces has a convenience `Faces#redirect()` method which automatically prepends context path and URL-encodes params. – BalusC Mar 09 '16 at 12:25
  • But how do I do it in primefaces? Copy OmniFaces source? I want to safely add params to a url which may already be containing a parameter. – user2918640 Mar 09 '16 at 13:17
  • OmniFaces is not a component library. It is an utility library which can be used with any component library. Even more, OmniFaces showcase application uses PrimeFaces. – BalusC Mar 09 '16 at 13:23