What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make a JSF 2 URL bookmarkable, declare incoming query parameters on the target view with <f:viewParam>, then generate a link to that view. Set includeViewParams to true when the link should include the target view’s declared parameters. The URL’s path depends on your FacesServlet mapping.

1. Declare the query parameter on the target view

In the Facelets view that should open from the bookmarkable URL, declare each accepted query parameter in <f:metadata>. For example, bind an id parameter to the target view’s model property:

<f:metadata>
    <f:viewParam name="id" value="#{itemView.id}" />
</f:metadata>

When JSF opens the view with a URL such as ?id=42, the declared view parameter gives JSF the mapping to bind that incoming value to itemView.id. Choose a model property appropriate to the parameter and validate or convert input as required by your application.

2. Generate a link to the view

For a rendered link, use a JSF link or button outcome that selects the target view, and supply the desired value through the component’s parameter mechanism. Enable includeViewParams when the generated URL should also contain the target view’s declared parameters. The exact component syntax available depends on the JSF version deployed, so check that version’s component documentation before copying a complete page example.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

At the API level, ViewHandler.getBookmarkableURL(FacesContext, viewId, parameters, includeViewParams) generates an action URL suitable for use as a link target. If includeViewParams is true, JSF obtains the parameters declared by the target view and adds them unless the supplied parameter map already contains the same name. An explicitly supplied parameter therefore takes precedence for a matching name. If the flag is false, JSF does not add those extra declared view parameters.

3. Account for the FacesServlet mapping

There is no single public URL shape for every JSF application. The application’s servlet registration and JSF mapping determine the path produced for a view; the Facelets source filename alone does not necessarily tell you the browser-facing URL.

  • Suffix mapping: A mapping such as *.faces produces a URL using that suffix, as described for JSF 2.3 in the specification.
  • Prefix or exact mapping: These follow their corresponding servlet mapping rules and can produce a different path shape.

Check the application’s FacesServlet configuration when verifying the final URL.

4. Know when a protected view adds a token

For a protected view, JSF may include a framework-generated non-postback view token in the action URL. The JSF 2.3 specification describes a token named by ResponseStateManager.NON_POSTBACK_VIEW_TOKEN_PARAM, containing a cryptographically strong session token that is checked during restore view. Treat it as JSF view-protection behavior: do not invent or hard-code it as an application parameter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Choose a bookmarkable link or a redirect

getBookmarkableURL creates a URL intended to be the target of a link in a JSF response. A redirect is a different navigation operation: getRedirectURL is intended for the NavigationHandler to issue a redirect using a non-Faces request. Use the link-oriented API when rendering a link; use redirect navigation when the browser should be sent to another URL as a response.

Implementation checklist

  • Declare each incoming query value on the target view with <f:viewParam>.
  • Point the link outcome at that target view and provide any desired parameter values.
  • Set includeViewParams to true if declared target-view parameters should be added to the link URL.
  • Remember that an explicitly supplied parameter wins when its name matches a declared view parameter.
  • Verify the visible path against the app’s servlet mapping, and account for framework token behavior if the target is protected.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.