The use case is calling a method on a JSF 2.x Backing Bean directly from a hyperlink (Non-Faces-Request). What is the best way to do this?
I imagine to do something like this:
The Link:
http://localhost/show.xhtml?id=30&backingbeanname=loaddata&method=load
The Backing Bean:
@Named (value = "loaddata")
public class DataLoader {
public void load(int id){ ... }
}
Use
<f:viewParam>in the target view to set GET parameters as bean properties and use<f:event type="preRenderView">to invoke an action on them.In
show.xhtml:In managed bean:
Note that in the above example the URL
http://localhost/show.xhtml?id=30is sufficient. You can always set more parameters as bean properties and have one “God” bean which delegates everything, but that’s after all likely clumsy.Also note that you can just attach a
Converterto the<f:viewParam>(like as you could do in<h:inputText>). Theload()method is then most likely entirely superfluous.See also: