Today, we want to add the next sneak peek of the Dolphin Platform, a new open source project Michael Heinrich and Hendrik Ebbers are currently working on. Yesterday, we blogged about the general concept of the platform. This blog post will show how server side controllers can be defined using the Dolphin Platform.
The Controller API
As already said, the controllers are defined on the server. If you already used JSF you might know this concept. But don’t be afraid, we won’t compare Dolphin Platform with JSF.
Each controller must be annotated with the @DolphinController annotation and therefore the most simple controller might look like this:
Even if this class doesn’t make that much sense, we created a complete runnable Dolphin Platform server application here. Once this is deployed the underlying platform (currently JavaEE or Spring) will automatically find your container and manage its lifecycle. This is done by the architecture of Dolphin Platform that provides a public API and specific bootstrap implementations for JavaEE and Spring. As a developer you will always code against the public API and only need to add the needed bootrap module as a dependency to your server application.
This means that the shown controller will work in any Spring or JavaEE 7 environment.
Since the controllers are managed by the container you automatically get all the benefits that comes with it. This means that you can use @Inject or @PostContruct annotations, for example:
Next to this Dolphin Platform provides additional features for the controller API. Any method that is annotated by @DolphinAction can be called from the client view to trigger some actions on user interaction, for example:
Thus, it’s very easy to handle the business logic that will be triggered by a user action. Since the methods are defined on the server you benefit of security and transaction support, for example.
Next to the actions a main concept of the Dolphin Platform is the presentation model (or view model). Each view-controller-pair can define it’s own model that can simply be injected in the controller by using the @DolphinModel annotation. We will see later how such a model can be defined. When injecting a model to the controller its lifecycle is bound to the lifecycle of the controller and will be automatically managed by the underlying platform.
With this procedure, the model instance will automatically be created when a new controller instance will be created. If the controller will be destroyed by the container the model will be destroyed, too. In addition, the model will automatically be synchronized between the server controller and the view on the client side. How the model can be accessed and handled on the client will be part of a future post.
I think the biggest benefit in the shown concept is the perfect integration in a web container like it is provided by Spring or JavaEE. All your controller (and model) instances will be managed by the container and it’s no problem to inject a spring service in your controller, for example. With this, you can use an API like Spring data and fill your view model directly with data from your persistence.
In the next preview we will show how a view model can be defined by using Dolphin Platform and how you can simply observe any view model on the server and client.