Writing a Model Processor

A model processor can be configured to work either for a single view or for multiple views. A model processor must

  • Extend com.escenic.framework.controller.processor.GenericModelProcessor

  • Override updateModel method

You might, for example create a model processor called HelloWorldWidgetDefaultViewModelProcessor for your Hello World widget's default view:

package com.mycompany.view.processor;

import com.escenic.framework.controller.processor.GenericModelProcessor;
import neo.xredsys.presentation.PresentationArticle;
import org.apache.commons.lang.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;


public class HelloWorldWidgetDefaultViewModelProcessor extends GenericModelProcessor {
  @Override
  protected void updateModel(final Map<String, Object> pWidgetModel,
                             final PresentationArticle pWidgetContent) {

    if (StringUtils.isNotBlank(pWidgetModel.get("greetings").toString())) {
      pWidgetModel.put("greetings", "Welcome");
    }
  }
}

You could use then access the contents of the resulting model object from your view JSP template as follows:

<h3>${widget.model.greetings}</h3>

Note that the modified widget model is cached, so the model processor is not executed every time a widget is rendered.

Before a model processor can be used it must be:

  • Compiled

  • Added to the web application's classpath

To compile a model processor you must have wf-presentation-4.0.3-1.jar in your classpath.

Once you have created a model processor class, you need to:

  • Create a set of properties files to declare the model processor and register it in the system

  • Package the model processor in a JAR file

  • Deploy the JAR file in your publication