-
Notifications
You must be signed in to change notification settings - Fork 1
Controller
Reaction on URL calls and generating such URLs obviously is closely related. Still generating URLs and later handling them are two separate things. In general URLs are used to achieve two goals: One being simply to view a certain page in a web application, the other being to trigger a certain function in the system and in return present a view of the results.
As a result URL generation and handling can be - like the Tangram system needs to do it - implemented in different parts of you application or be implemented in common classes doing both if appropriate.
We avoid terms like "MVC" here, since Tangram is not really aware of which pattern you are actually using.
With Tangram URLs are most times not written "manually" into the results of the view
layer. URLs are generated by the system to relate to some URL handling part of your
application. Most likely this generation is triggered by some JSP tag (<cms:link>
)
or Apache Velocty directive (#link
) with the instances to generate links for as
parameters.
To add link generation functionality, the ˋLinkFactoryˋ interface has to be implemented. There can - and should - be more than one such factory implementation to seperate different parts of the application also in this aspect. So only generate links for a certain context or class of objects in one link factory implementation.
Link factories not only return the URL, the Tangram Link
interface provides the
possibility to have more information at hand for the generation of the corresponding
view later. In the URL part of the result, the web application prefix (or web application
context) should not be included so that link factory implementations are independent
of the web application configuration in the deployment.
To collect the functionally of all the link factory implementations available, an aggregator instance is introduced into the systems. All link factory implementations in use must be registered with it to be take into account by the link generation in the view layer.
The link factory aggregator uses the factory instances to check which of them is able to generate a valid (non null) url for the given context (e.g. request, object, view), adds the preview (web application context name) to the returned URL and returns the result to the view layer.
It is possible but very unlikely that you will use the aggregator directly for any other purpose than registering link factory instances with it.
When using the spring framework flavour of Tangram it might be a good idea to use
any of the controller implementation facilities of that framework. Spring definitely
provides a broader range of possibilities than the Tangram LinkHandler
s at the
cost of portability.
Some LinkFactories have to be added to generate the URLs handled by your controllers.
Please use the spring aware implementation of the ˋViewUtilitiesˋ interface to pass over the results of your controller to the view layer.
This is in fact how Tangram started its URL call handling. So, if Spring is your choice you can use @Controllers to implement your URL handling behaviour. Some link factories have to be added to generate the URLs handled by your controllers.
Please use the spring aware implementation of the ˋViewUtilitiesˋ interface to pass over the results of your controller to the view layer.
If you take the possible flavours of Tangram and the environments into account, there is only one common API to handle the behaviour for reactions on HTTP requests: The Servlet API.
Since this is a very low level API you still can use it to implement you own request handling, but are strongly encouraged to use at least Tangram LinkHandlers of any kind in such situations, since it avoid much boiler plate code.
Tangtram intriduces its own way of handling URLs for two reasons. The first one being simply that there is no other common ground between the frameworks of Spring and Guice (and CDI) except servlets which means reinventing the wheel every time. The second reason is, that this way it is possible to extend the URL handling and generating parts of Tangram (just not to call it controllers) dynamically at runtime with groovy implemented components.
An implementation of the LinkHandler
interface is the symmetrical extension of the
LinkFactory
: It adds the parsing of the URL and returning of a description what to
pass over to the view layer through an instance of the TargetDescriptor
class.
LinkHandler implementations need to be registered with the LinkHandlerRegistry te be taken into account.
Also @LinkHandler annotated implementations need to be registered with the LinkHandlerRegistry
to be taken into account.
ViewUtilities, Max upload size, UniqueHostHook, UniqueURLHook