Server side controllers

Webpagebytes CMS uses the MVC (Model-View-Controller) concept to generate content.
Site pages represent the View component in the MVC pattern. The Model component is generated by the CMS engine implementation and can be populated with application specific data by custom application Controllers. An application that integrates Webpagebytes CMS can define custom code that can interact with the content, this custom code represent the Controller(s) part of the MVC pattern.

A controller can include code that:

There are two types of controllers

Type Controller interface Description
Url controller com.webpagebytes.cms.WPBRequestHandler Controller associated with a site url, and called on every HTTP request of that site url
Page model provider com.webpagebytes.cms.WPBPageModelProvider Controller associated with a site page, and called every time when the site page is used to generate content

The Model

The Model represents the aplication data and it's the one that makes the link between the application behaviour (the Controllers) and the application View.

Webpagebytes CMS represents the model with the WPBModel class.
For each HTTP request handled by the CMS that uses controllers, the CMS engine will create a WPBModel instance.

There are two types of data that can be handled by the WPBModel

WPBModel CMS specific data

Url controller

A Url controller implements WPBRequestHandler interface. This interface purpose is to define behaviour and content for a site url HTTP request.

public interface WPBRequestHandler 
    public void initialize(WPBContentProvider contentProvider);
    public void handleRequest(HttpServletRequest request, 
                              HttpServletResponse response, 
                              WPBModel model,
                              WPBForward forward) throws WPBException;

A site url can have its resource type value as Url controller, in which case the application will need to implement WPBRequestHandler interface. Usually each such site url will have its own concrete implementation of WPBRequestHandler.

The method initialize of WPBRequestHandler is called once when the controller is instantiated by the CMS engine. WPBContentProvider instance can be used to fetch content provided by the CMS, this content can be used to generate other content.

On each HTTP request associated with such a site url, the method handleRequest will be called by the CMS engine.
WPBModel reference represents the Model component from the MVC pattern and can be used to access Webpagebytes CMS specific data to the current request, or to populate the model with application specific data.

A controller can adopt multiple strategies for its code logic:

Page model controller

A Page model controller implements WPBPageModelProvider interface. The interface purpose is to populate the request WPBModel with custom application data that will be used by a site page to generate the HTTP response content.

public interface WPBPageModelProvider {
	public void populatePageModel(WPBModel model) throws WPBException;

A page model provider implementation cannot influence the HTTP request directly (it cannot redirect to other url, it cannot change the site page associated with the current request). The implementation will just fetch data from application specific location (for example from a database, or from a web service) and will populate the model with this data. The site page template script is responsible to display the content provided in the WPBModel instance.