I've upgraded a JSF application from 1.1 to 2.0 and I'm trying to encode request parameters after performing an action.

The situation:

  • The user presses a save-button on viewA.xhtml which invokes save() on a backing bean A. After the save() is performed successfully I navigate to viewB.xhtml?faces-redirect=true.
  • View B, which is navigated to, defines a couple of view parameters (f:viewParam).
  • The two views currently have to use different backing beans.
  • The button must be a commandButton such that a action method is invoked prior to the navigation so I cannot use a regular button with f:param elements.

I found another issue already solved Passing parameters with h:commandButton -- or the equivalent but I'm dependent on the redirect.

有帮助吗?

解决方案

Just pass those parameters along in the redirect URL.

String outcome = String.format(
    "viewB?faces-redirect=true&foo=%s&bar=%s",
        URLEncoder.encode(foo, "UTF-8"),
        URLEncoder.encode(bar, "UTF-8"));

return outcome;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top