The sample you are asking for is not really native to how JSF works.
Query-based frameworks such as Struts and Spring MVC , and the old Servlet / JSP approach for Model 2, actually worked like this.
In JSF, first of all, it is a page (view) that is automatically mapped to the request URL. There is no concept of a bean that maps directly to a URL, and no concept of a bean that has a structure associated with a 1: 1 relationship with a view. However, there is a concept of bean support, but this is consistent. For JSF, all beans are "auxiliary beans" that are simply referenced by the view.
BalusC outlined popular ways that can be used today to get some of the behavior from query-based frameworks in JSF in his answer. JSF 2.2 will expand this support a bit by introducing a view action that formalizes a few typical use cases for preRenderViewEvent .
However, JSF is a very flexible structure, and very few things are set in stone. Many JSF actions can be replaced or added through a complex system of plugins and decorators.
For this use case, the fact that JSF associates URLs with Facelets can be overridden, and you can really let beans respond directly to requests. Although for a slightly different purpose, I did this for JavaVDL , overriding the so-called view handler.
You should ask yourself if this is really what you want to do, and if you want to work that way, is JSF the best choice for you. But using the methods described in JavaVDL ( sourcecode here ), you have to do this. Please note that this last method is not suitable for beginners and requires quite a lot of JSF experience if you want to take it off yourself. (If you or anyone else would like to have this functionality, consider creating a problem for it in the OmniFaces problem list ).
source share