What Do We Really Need From A Controller?

A Discussion Paper
By Duncan Mills

Over on the Apache Struts Development list server discussions have been going on about the proposals for Struts 2.0 (aka "Shale"), in concert with this we have Erwin Vervaet's Spring Web Flows recently announced. All of this has got me to thinking. What do we really need from a Controller? We have a lot of competing frameworks out there, each with a world view and enthusiastic user base, is this a race that needs to be won or has no-one defined the finish line yet?

Name the Beast

So first of all what is a Controller? Even in the clinical world of the Model View Controller (MVC) architecture the Controller is a somewhat schizophrenic, just take a look at the Core J2EE Patterns index diagram published by Sun, as an example. We have multiple instances of the Front Controller pattern liasing with View Helpers and a Dispatcher. If you think about an established Controller framework such as Struts, these are all mushed together into a monolithic Controller framework, is this approach still relevant in today's J2EE development?

Looking at development for today's systems we may well have to think about integrating with technologies such as Portals or JavaServer Faces (JSF), situations in which there is already an owner of the Front Controller role and potentially the View Helper role as well.

JSF is an interesting example, if I think about the Controller in Faces I'm really just thinking about Faces Navigation. All of those other "Controller" roles are there, but handled by the View framework itself in a front controller role. So the controller is shrunk down to not much more than a simple dispatcher. Is this enough? Does JSF offer me all of the functionality and maintainability that I would get from a fatter Controller framework such as Struts? My heart tells me that the answer is No, I do need more functionality than the simplistic navigation model in JSF can offer, but in turn leads me back in a circle to this question of what exactly it is that I think I need.

This fundamental problem of the exact definition of the Controller role needs to be resolved. It is inevitable that there will be bleeding at the edges where the controller interfaces with the View in particular, and the degree of overlap will differ based on the View technology being used. (If we take the assumption that a Controller framework should be View agnostic, which I think is uncontested). So lets look at some of the things that a controller must do and could do.

Things A Controller Must Be And Do

Things A Controller Could Do

In Conclusion

This article has been all about throwing a few ideas out there with an aim to gather consensus as to what the problem is that a Controller framework is trying to solve. We are at a pivotal time with respect to both JSF and Struts Shale and indirectly with the percolation of J2EE adoption into the larger business programmer community. One big question remains of course, is the Controller role something that should be standardised? We have standards now for UIs in JSF, persistence and business logic in EBJ, JSR227 offers another piece of the puzzle with respect to data binding, but the Controller is still one of the larger missing pieces. It's worth thinking about.

 

© Duncan Mills 09/Nov/2004

Version 1.0 http://www.groundside.com/blog