ViewControllers in Orchestra

Sure, the “ViewController” pattern isn’t new. Basically it is the concept of using a specific bean, behind a webpage. In ASP.NET this is called code-behind, AFAIK. Apache Shale has it, and Apache MyFaces Orchestra too.

It might be confusing, that two Apache projects provide the same facility, but that happens🙂

Basically your bean (that lives inside the (Spring) configuration) is named similar like the JSF viewId.
A viewId “editor.xhtml” will map to a bean, named “editor”. A viewId like “staff/editor.xhtml” will map to a bean, that is named “staffEditor”. Not hard to understand.

I personally like the Orchestra ViewController more, compared to the Shale ones. Sure Shale was one of the first implementations out there, that were providing this mechanism for JavaServer Faces. Perhaps JSF 2.0 has something like that ? Let’s wait and see…

Orchestra’s ViewController provides three callbacks:

  • initView (called after the JSF RESTORE_VIEW phase)
  • preProcess (called before the JSF INVOKE_APPLICATION phase)
  • preRenderView (called before the JSF PRE_RENDER phase)

Not enough, there are currently three options to use them:

  • implementing the ViewController interface
  • using Java Reflection
  • using Annotations

The interface way is easy, just implement the interface and its three methods and you are done. The reflection approach is quite interesting. You can have a simple POJO like:

public class CreateController
{
public void initView()
{
...
}
...
}

and your code is called by the framework. No interface or annotation needed. Pretty neat, isn’t it?

Using annotations also has its charm. You can annotated the class with different viewIds and some methods, like:

@ViewController(viewIds={"/all.xhtml"})
public class AllController
{
...
@PreRenderView public void loadUsers()
{
...
}

That enables you to have serveral view to reuse the same ViewController.

More soon!

Howdy!

Posted in Uncategorized
One comment on “ViewControllers in Orchestra
  1. Mehmet Ates says:

    Hallo Matthias,
    Ich habe das Interface ViewController implementiert, aber die Methoden initView, preProcess und preRenderView werden nicht aufgerufen. Für eine Idee wäre Ich dankbar.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: