Controller Events
Requests can be used as to trigger events. Like all request definitions, these are defined within the Controller . Controller events are either request-specific or generic. The difference is that generic events are validated on each request without validating the request path itself.
Annotation
@Event(name = "test", type = "java", path = "org.ofbiz.webapp.event.TestEvent", invoke = "test",
section = "postprocessor")
public interface PostprocessorTestEvent {}
@Request(
uri = "view",
secure = "false",
auth = "false"
)
@Event(name = "test", type = "java", path = "org.ofbiz.webapp.event.TestEvent", invoke = "test")
@Response(name = "success", type = "request", value = "main")
public interface View {}XML
<?xml version="1.0" encoding="UTF-8"?>
<site-conf xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/site-conf.xsd">
<!-- event handlers -->
<!-- Generic events -->
<preprocessor>
</preprocessor>
<postprocessor>
<event name="test" type="java" path="org.ofbiz.webapp.event.TestEvent" invoke="test"/>
</postprocessor>
<after-login>
</after-login>
<before-logout>
</before-logout>
<firstvisit>
</firstvisit>
<!-- Request Mappings -->
<request-map uri="view">
<security https="false" auth="false"/>
<!-- Request event -->
<event name="test" type="java" path="org.ofbiz.webapp.event.TestEvent" invoke="test"/>
<response name="success" type="request" value="main"/>
</request-map>
<!-- View Mappings -->
</site-conf>When more than one event is defined, the events will be triggered in a chain. So it is possible to reuse the same event structure to maintain a request-flow. All events rely on the following attributes:
| Attribute | Description |
|---|---|
| name | Event name |
| type | Type of event to be run. Relies on handler definition (/framework/common/webcommon/WEB-INF/handlers-controller.xml). Available options:
|
| path | Location or classpath |
| invoke | method name to run |
| global-transaction | For service-multi, defines if the event should be wrapped in a transaction, default to true (default: true)Available options:
|
Generic controller events#
Generic controller events are run on each request. There are five different events available:
- Preprocessor (Run on every request before security)
- Postprocessor (Run on every request after all other processing)
- firstvisit (Run the first time a request is made in the current session)
- after-login (Run after the user has been authenticated)
- before-logout (Run after the user has logged out)
Request Events#
The request specific events are defined for a specific request and are tightly connected to request-maps. The response is interconnected to the service result and uses the service or event response to define a response type. This way it is possible to use events to control the overall request-flow, a concept that is largely used throughout the application.
Annotation
@Request(
uri = "view",
secure = "false",
auth = "false"
)
@Event(name = "test", type = "java", path = "org.ofbiz.webapp.event.TestEvent", invoke = "test")
@Response(name = "success", type = "request", value = "main")
public interface View {}XML
<!-- Request Mappings -->
<request-map uri="view">
<security https="false" auth="false"/>
<!-- Request event -->
<event name="test" type="java" path="org.ofbiz.webapp.event.TestEvent" invoke="test"/>
<response name="success" type="request" value="main"/>
</request-map>