Writing a Widget Processor
A widget processor is a Java class that performs some action every time a widget is rendered. A widget processor can be configured to work either for a single view or for multiple views. A widget processor must
-
Extend
com.escenic.framework.controller.processor.GenericWidgetProcessor
-
Override
process
method.
You might, for example, create a widget processor called
HelloWorldWidgetDefaultViewWidgetProcessor
for your
Hello World
widget's default
view:
package com.mycompany.view.processor; import com.escenic.framework.controller.processor.GenericWidgetProcessor; import neo.xredsys.presentation.PresentationArticle; import javax.servlet.http.HttpServletRequest; import java.util.Map; public class HelloWorldWidgetDefaultViewWidgetProcessor extends GenericWidgetProcessor { @Override protected void process(final Map<String, Object> pWidgetContext, final HttpServletRequest pRequest) { PresentationArticle article = (PresentationArticle) pRequest.getAttribute("article"); pWidgetContext.put("viewCount", getViewCount(article)); } }
Assume that the getViewCount()
method returns the
number of times the current article has been viewed. Your widget
processor adds this value to pWidgetContext
, the
widget context bean, so that it can then be
retrieved by a view JSP template. For example:
<p>This page has been viewed ${widget.viewCount} times.</p>
The widget context bean provides access to all data associated with the context widget (including its model object). For further information, see Using The Widget Context Bean.
Before a widget processor can be used it must be:
-
Compiled
-
Added to the web application's classpath
To compile a widget processor you must have
wf-presentation-4.0.3-1.jar
in your classpath.
Once you have created a widget processor class, you need to:
-
Create a set of properties files to declare the widget processor and register it in the system
-
Package the widget processor in a JAR file
-
Deploy the JAR file in your publication