Creating Custom Segments
  • 16 Apr 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light

Creating Custom Segments

  • Dark
    Light

Article summary

Introduction

The document describes briefly how to create custom segments in Comflow.

Background

In earlier versions of the platform, custom segment creation was made using XSLT technology. Due to the limitations in performance with this technology, in version 2.16, the entire rendering engine has been re-written from scratch, and now, a Java object model is used, and each node in that model is responsible for creating its own HTML. This not only enhances performance vastly, but also enables debugging of the rendering, which was not possible before.

In order to follow this new rendering approach, each custom xslt in earlier versions must be written in Java instead. This might be considered an effort, but on the other hand, all HTML written in XSLT is already there, and you should quite easily be able to move that HTML to your Java code instead, with performance and debugging ability as benefits.

Custom Segment

Creating a custom segment mainly consists of two parts – creating the Java file, which generates the HTML, and setting the flow segment Custom Segment Reference property pointing to that file in your portlet.

AbstractCustomSegment

This class is the abstract implementation of the custom segment framework. It is supposed to be extended by all implementers that want to create a custom segment. The extension of this class must be pointed to in the flow segment Custom Segment Reference property in the portlet.

There are three methods involved in the rendering process.

  1. preRender - this method sets up some general starting html for the segment i. e. the segment header. If you want a header, and have the header text controlled with a constant, you can override the getConstantMetadataId() and the getConstantId() methods in your custom segment class. You can also tell that the segment header should not be rendered by invoking the setCreateHeader method with a false boolean. This method can be overridden to create a custom header.
  2. customRender - this is the abstract method that your custom segment class must implement, and this is where you create your custom HTML.
  3. postRender - this method wraps everything in the meaning of closing the segment properly. This method can be overridden.

All three methods take two parameters, the print writer to where you write your custom HTML, and the renderer info object. The renderer info object contains useful data, for instance process data, which is very useful when creating your own sql statements.

Example Segment

Below you see an example of a custom segment. The segment does not override the preRender, and postRender methods. The customRender method writes a paragraph containing some text, and the getLabelText() method is overridden to return a title for the segment.

public class MyCustomSegment extends AbstractCustomSegment {

public void customRender(PrintWriter out, RendererInfo rendererInfo) {

// message

out.print("

");

out.print("You have successfully rendered your own custom segment.

Congratulations!");

out.print("

");


}

@Override

public String getLabelText() {

return "My first custom segment";

}

}

Portlet Editing

Create a new portlet or open an existing one. Create a flow segment, and open the Advanced property tab. Edit the Custom property by saying true, and edit the Custom Segment Reference property by using the file dialog to point to your custom segment class.

Save, deploy, and run.



Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.