• Post Reply Bookmark Topic Watch Topic
  • New Topic

controller in JSF

 
Rauhl Roy
Ranch Hand
Posts: 401
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If MVC can be implemented through JSF may i know what is the Controller here in JSF?
 
leo donahue
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Speaking to Sun JSF 1.2 RI

The Faces Servlet is where everything starts and is defined in web.xml

The controller in JSF is used for navigation, or actions or validation. The controller can be any POJO method that returns a string that is used to handle page navigation. Page navigation is defined in the faces-config.xml using a navigation-case element. The method is tied to a form submit or some other form element.

The Java EE 5 Tutorial - What is a JavaServer Faces Application.

Adding a button
See how the h:commandButton has an action of "sucess" ? That value comes from a backing bean you define and as a result something happens; page navigation, validation, custom message, etc.

[edit]
In the sense that you are thinking of a controller as a servlet that processes the request, creates other beans, forwarding to other pages, etc. then in JSF the controller is still really the same as it has been.

 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's a bit more than that, but then so is MVC. What a lot of people don't realize is that:

A) MVC isn't about a master controller that micro-manages everything, it's about a master View controller which handles the overall View and then optional sub-contollers which generally manage sub-views.

B) MVC separates the Model, View, and Controller specifically so that the same backing data (Model) can be used with different View and Controller sets to provide multiple views at the same time. For example, a pie chart in one View and a table in another view, both tracking the same model. Not particularly applicable to JSF, but it's part of the mindset.

The FacesServlet is the master controller. However, the JSF tag elements all provide sub-controllers appropriate to the types of sub-views they support. Such as the DataTable, the SelectOneMenuList and the InputText controls.

Just to further confuse the issue, JSF backing beans aren't 100% pure Model objects. ValueChangeListeners, for example perform Controller functions and I'd lump Converters in there as well.

The bottom line, however, is that in JSF little or no user-create Controller code is required. JSF does most of its magic using simple off-the shelf components.

In fact, that's one of the most common mistakes a lot of people make. They try and code up all sorts of "JSF code" when JSF doesn't need it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!