0

I was trying to understand how to perform PRG on a JSF app using this link https://blogs.oracle.com/enterprisetechtips/entry/post_redirect_get_and_jsf but somehow I got confused on three items.

  1. From the blog, I see from firebug that it is issuing a 302 and GET redirect when rendering pages instead of the POST method which is a PRG. The only changes in the blog is the scope of the bean from being a session scoped to a request scope. SO does this link suggest that all my managed bean be at Request Scope level? I check my sample app that I am doing and I am heavily using ViewScoped and SessionScope beans.

  2. Whats the usefulness of ViewParameters? Arent that a security problem, supposed I add more query string parameters at the url? I am actually finding a use case on where can I used such feature.

  3. If the transaction that I am doing will not do any transactional nature such as ADD/EDIT/DELETE, is it still a good practice to just merely use the JSF navigation which is a POST request? I just wanted to navigate to a new page.

Thanks

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186

1 Answers1

1

So does this link suggest that all my managed bean be at Request Scope level? I check my sample app that I am doing and I am heavily using ViewScoped and SessionScope beans.

The bean's scope doesn't matter for the PRG itself. It only matters for the lifespan of the data the bean holds. See also How to choose the right bean scope?


Whats the usefulness of ViewParameters? Arent that a security problem, supposed I add more query string parameters at the url? I am actually finding a use case on where can I used such feature.

The includeViewParams will only include the parameters which you've manually specified in <f:metadata><f:viewParam>. It will not include all original query parameters. This is not necessary for the PRG itself. Whether to use it or not depends on the concrete functional requirements. The article just shows that it's possible to copy all view parameters into the redirect URL, which may be useful/mandatory for some functional requirements. See also What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?


I just wanted to navigate to a new page.

Use <h:link> instead of <h:commandLink>.

<h:link value="Go to next.xhxml" outcome="next" />

See also When should I use h:outputLink instead of h:commandLink?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555