Heads up! These docs are for Portofino 3, which is a legacy product. Check out Portofino 4!

Copyright 2008-2012 ManyDesigns srl. All rights reserved.


Listener allow you to intercept (create, update, delete) operations on objects. Listeners in ManyDesigns Portofino are similar to triggers in relational databases.

When are listeners executed?

Every listener has six actions that are executed in six different situations, as shown in the following table:

   Executed before DML  Executed after DML
 Create pre create  post create 
 Update  pre update post update 
 Delete  pre delete post delete 

The difference between a "pre" and a "post" operation is in the temporal relationship with respect to the DML commands (INSERT, UPDATE, DELETE) Portofino uses to persist its objects. The order is:

  • first, all "pre" actions are executed on the objects that need to be persisted;
  • then, the objects are persisted through DML commands;
  • finally, all "post" actions are executed.

In a "pre" action, you can assume that no object has been written to the database. In a "post" action you can assume all objects have been written.

Types of listeners

There are two types of listeners: script class listeners and Java class listeners. They fill exactly the same purpose and functionality. What varies is their implementation. Script class listeners are written as BeanShell scripts through Portofino's web interface. Java class listeners are written as a Java classes and need to be complied outside Portofino.

All listeners have the following common fields:

  • Class: the class of object that will execute this listener.
  • Name: the listener's name, for the modeler.

To create a listener, choose the class you want to add it to. Go to the class' details page upstairs, scroll down to the Listeners section. View any listener that may already be available, or click "Add listener" to create a new one.

Script class listeners

A script class listener has six text fields where you can write a script directly in BeanShell syntax:

  • Pre create
  • Post create
  • Pre update
  • Post update
  • Pre delete
  • Post delete

Inside the script, the following variables are pre-set by Portofino:

  • obj: the object for which the listener is executed.
  • cls: the class to which the listener is bound.

Java class listeners

A Java class listener has one specific attribute:

  • Java class: the full name of the Java class implementing the listener.

The Java class you provide must implement the com.manydesigns.portofino.base.MDClassListenerinterface and be available in the classpath.


Previous: Custom operations

Next: Single sign-on