Java event handler example
Like the JavaScript event handler in the previous section, the Java code example in
Listing 21‑2 uses the getUserRoles( ) method to retrieve the user’s roles and displays the contents of a table if the user role is Manager. The TableEH class extends the TableEventAdapter class and implements the event-handler script in the onPrepare event method.
Listing 21‑2 Java event handler class
package server.api.eh;
import java.util.List;
import org.eclipse.birt.report.engine.api.script.IReportContext;
import org.eclipse.birt.report.engine.api.script.element.ITable;
import org.eclipse.birt.report.engine.api.script.eventadapter.TableEventAdapter;
import com.actuate.reportapi.engine.IServerContext;
public class TableEH extends TableEventAdapter {
public void onPrepare(ITable tbl, IReportContext reportContext)
{
IServerContext scontext;
scontext = (IServerContext)reportContext.getAppContext().get("ServerContext");
List<String> userRoles = scontext.getUserRoles();
scontext.appendToJobStatus("The user roles are:" + userRoles+"\n");
for (int i = 0; i < userRoles.size(); i++)
{
if ( userRoles.get(i).contentEquals("Manager"))
{
reportContext.setGlobalVariable("HideDetails", "false");
scontext.appendToJobStatus("The user has a Manager role\n");
break;
}
}
}
}