public class OpenEntityManagerInViewListener extends java.lang.Object implements ExecutionCleanup, ExecutionInit
In WEB-INF/zk.xml, add following lines:
<listener>
<description>Hibernate "OpenEntityManagerInView" Listener</description>
<listener-class>org.zkoss.zkplus.jpa.OpenEntityManagerInViewListener</listener-class>
</listener>
Applicable to EJB version 3.2.ga or later
Constructor and Description |
---|
OpenEntityManagerInViewListener() |
Modifier and Type | Method and Description |
---|---|
void |
cleanup(Execution exec,
Execution parent,
java.util.List errs)
called when an execution is about to be destroyed.
|
protected void |
handleException(Execution exec,
java.lang.Throwable ex)
Default exception handler.
|
void |
init(Execution exec,
Execution parent)
Called when an execution is created and initialized.
|
public void cleanup(Execution exec, Execution parent, java.util.List errs) throws java.lang.Exception
ExecutionCleanup
If this method throws an exception, the stack trace will be logged, and the error message will be displayed at the client.
When this method is invoked, the execution is still activated, so you can create components here.
cleanup
in interface ExecutionCleanup
exec
- the execution to clean up.parent
- the previous execution, or null if no previous at allerrs
- a list of exceptions (java.lang.Throwable) if any exception
occurred before this method is called, or null if no exception at all.
Note: you can manipulate the list directly to add or clean up exceptions.
For example, if exceptions are fixed correctly, you can call errs.clear()
such that no error message will be displayed at the client.java.lang.Exception
public void init(Execution exec, Execution parent) throws java.lang.Exception
ExecutionInit
Note: this method is called after exec is activated. In other words,
Executions.getCurrent()
is the same as
the exec argument.
When this method is called, you can retrieve the current page with
ExecutionCtrl.getCurrentPage()
.
However, the page is not initialized yet. In other words,
Page.getDesktop()
,
Page.getId()
and Page.getTitle()
all return null.
To get the current desktop, you have to use
Execution.getDesktop()
(from
Executions.getCurrent()
) instead.
On the other hand, you can set the page's ID, title or style in
this method (to override the declarations in the page definition)
by Page.setId(java.lang.String)
, Page.setTitle(java.lang.String)
and Page.setStyle(java.lang.String)
.
In additions, Page.getRequestPath()
and Page.getAttribute(java.lang.String, int)
are all available.
init
in interface ExecutionInit
exec
- the execution being created.parent
- the previous execution in the same (Servlet) request, or
null if this is the first execution of the request.java.lang.Exception
protected void handleException(Execution exec, java.lang.Throwable ex)
Default exception handler. This implementation simply rollback the transaction.
Application developer might want to extends this class and override this method to do other things like compensate for any permanent changes during the conversation, and finally restart business conversation... what can be done here depends on the applications design.
exec
- the execution to clean up.ex
- the Throwable which is not handled during the executionCopyright © 2005-2021 Potix Corporation. All Rights Reserved.