I'm going to answer your questions based on my own experience. Some of them are so open that more than one answer could fit.
A page forward is the way to go unless you explicitly require the browser url to be changed. A page forward is basically faster than a redirection as it requires less steps. A page redirect is required if you want to make your views bookmarkable.
Use <h:commandLink />
/<h:commandButton />
only when you need to POST the server. Later on, you'll be able to perform a page forward or a redirection depending on what the method returns. As an example:
<h:commandLink action="#{bean.processForm}" value="Submit" />
public String processForm(){
try{
save();
return "list";
}
catch(Excepcion e){
addFacesMessage("Error saving");
//Error saving the object, keep in the same view
return null;
}
}
Use <h:link outcome="list" value="Go to list" />
for pure page to page navigation within the JSF application. You can use either page forward and redirect. Use <f:param />
to pass view parameters.
<h:outputLink value="www.stackoverflow.com" />
could be used for external links to other sites (not into your application). Use <f:param />
to pass view parameters. I however prefer to use plain HTML with <a href="www.stackoverflow.com" />
myself for this case.
As for passing parameters to action methods in POST requests, you've got several options. f:setPropertyActionListener
was so popular in JSF 1.x, but if you're already at 2.x I would recommend you going with EL 2.2, which allows method parameter declaration. Being able to use it depends on the application server you're using, but even if not available you could import yourself. Then, you'll be able to do things like that:
<h:commandButton action="#{bean.saveCar(currentCar)}" value="Save Car" />
Use it wherever you can, it'll make things just easier.
For the view parameters, use <f:viewParam />
too. It's the standard JSF way of parsing the parameters from the GET request, so just let the framework do the retrieving work for you!
See also: