Reply To: What happened to PrettyFaces?

Splash Forums PrettyFaces Users What happened to PrettyFaces? Reply To: What happened to PrettyFaces?

#24185

I see two options if you want to navigate from non-JSF code:

1. Use constant and AddressBuilder

Use a constant for the path:


@Join(path = RecoveryBean.PATH, to="/faces/passrecovery.xhtml")
public class RecoveryBean {

  public final String PATH = "/passrecovery/{lang}/{token}/";

}

And then navigate like this:


String url = AddressBuilder.begin()
    .path(RecoveryBean.PATH)
    .set("lang", "en")
    .set("token", "29b4033ca6f93ae78495108b629f3ec3fda055a0")
    .toString();

response.sendRedirect(url);

I like this one because the pattern for the path is the same for the annotation and for AddressBuilder, so using a constant makes things really easy.

2. Use Navigate and encode URL

You can also use Navigate to create a standard JSF URL and than use HttpServletResponse.encodeURL() to create the pretty URL.


String uglyUrl = Navigate.to(RecoveryBean.class)
    .with("lang", "en")
    .with("token", "29b4033ca6f93ae78495108b629f3ec3fda055a0")
    .withoutRedirect()
    .toString();

/*
 * after that 'uglyUrl' will be:
 *    /faces/passrecovery.xhtml?lang=en&token=29b4033ca6f93ae78495108b629f3ec3fda055a0
 */

String prettyUrl = response.encodeURL(uglyUrl);

/*
 * after that 'prettyUrl' will be:
 *    /passrecovery/en/29b4033ca6f93ae78495108b629f3ec3fda055a0/
 */

response.sendRedirect(prettyUrl);

Please note .withoutRedirect() which is important to add so that Navigate creates a standard JSF URL.