Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Launching the WebViewer from code
m3t4bill
Hey, so first I'll give my version info and a brief description of what I'm trying to do:
Versions: BIRT (2.3.1), Eclipse (3.4.1), Flex (3), Tomcat (6)
Goal: To generate a report using an XML Stream as the data source, to be displayed in the WebViewer
Based on some other examples I found online, I found that to run my report with dynamic xml data, I had to write some code that set some values in the app context for my report via the following lines:
contextMap.put("org.eclipse.birt.report.data.oda.xml.inputStream", bis);
contextMap.put("org.eclipse.birt.report.data.oda.xml.closeInputStream", new Boolean(true));
I put this code in a custom servlet that I wrote, which eventually calls task.run() to display the report; everything works fine (report shows as html).
My question is, how can I make this report display in the WebViewer? I would like to take advantage of the AJAX report viewer with the export/print/etc functionality built in, but I can't seem to find how to get this working.
I found examples of people using WebViewer.display(...), but I don't have access to that from my code. Also, I CAN run reports in the WebViewer by calling into the /frameset servlet, but I can't seem to find how to do that while supplying my dynamic XML data as the source to the report!
Am I WAY off base with what I'm trying to do here? Thanks for any help you can give, let me know if you need any more information!
-Bill
Find more posts tagged with
Comments
JasonW
Bill,
Using the WebViewer.display() methods are used when deploying the viewer plugin in an RCP application. If you are doing this you can setup the appcontext like:
1 - Add a class to your application tha extends AppContextExtension
package org.eclipse.birt.examples.rcpviewer;
import java.util.Map;
import org.eclipse.birt.examples.rcpviewer.PreviewBirtAction;
import org.eclipse.birt.report.viewer.api.AppContextExtension;
public class MyAppContext extends AppContextExtension{
@Override
public Map getAppContext(Map appContext) {
Map hm = super.getAppContext(appContext);
//this has to be set on the engine not the task
//hm.put("PARENT_CLASSLOADER", PreviewBirtAction.class.getClassLoader());
String testStr= "This is a test of the appcontext";
hm.put("testAppContext", testStr);
return hm;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "MyAppContext";
}
}
Add the extension point to your plugin.xml
<extension
point="org.eclipse.birt.report.viewer.appcontext">
<appcontext
class="org.eclipse.birt.examples.rcpviewer.MyAppContext">
</appcontext>
</extension>
Finally in your code call this method before calling WebViewer.display()
ViewerPlugin.getDefault( ).getPluginPreferences( ).setValue("APPCONTEXT_EXTENSION_KEY", "MyAppContext");
AlexI
Hi Jason,
thanks for posting useful information, i have the same situation as Bill has and tried to use the steps that u describe.
I did exactly what u wrote, in both my RCP Project and in the rcpviewer example and got the same result:
an exception saying that MyEventHandler class can not be found. This is the event handler of the scripted data set, in it i try to access the Application Context. Any ideas on what could cause that? Thanks.
And something else, when you say "Add the extension point to your plugin.xml" you mean the plugin.xml of the project or the one of the WebViewer?
AlexI
OK, for all those that might have the same issue as i had in my last post, the solution is that BIRT WebViewer requires the compressed as jar file of Event Handler of the Scripted Data Set to be placed in its scriptlib directory located at: <em class='bbc'>your_webviewer_location/birt/scriptlib</em><br />
<br />
My further questions to Jason and others that might know and help me get up and running the upper posted class is:<br />
<br />
How do i use correctly insde the Event Handler the class MyAppContext that extends the AppContextExtension, or more specifically the Overriden method .getAppContext(Map m)..... ?<br />
<br />
At this moment i tried more versions but none worked:<br />
<br />
- The classical version inside the Event Handlers beforeOpen() method using the IReportContext parameter trying to call the .getAppContext()... but this is another version of the function, not the one that we are overriding inside the MyAppContext class.... so it doesnt return anything... <br />
<br />
- I also tried inside the same beforeOpen() method to create a MyAppContext object and call on it the overriden .getAppContext(Map m) this seems to work till the last line of the of this method where it throws a nullpointer exception on the line: "hm.put("MyAppContextTest", testStr);".<br />
<br />
Any ideas what is the way to go here??<br />
<br />
I would appreciate very much any sort of help.
m3t4bill
Hey, so I'm still a little unclear on a piece of this. It appears that WebViewer.display(...) will read the context file with the report data and encode this data into the URL using the &/= syntax. We are passing a large XML String as the report data, and the size of the encoded URL exceeds the maximum allowed size. What is the correct way to generate a report using dynamically generated XML as the data?
Thanks, I appreciate any feedback.
- bill
JasonW
Bill/Alex
You should be able to replace
String testStr= "This is a test of the appcontext";
hm.put("testAppContext", testStr);
in the getAppContext of the MyAppContext class with whatever you want to preload into the application context. In the event handler class or script you should be able to access your object by calling
reportContext.getAppContext().get("testAppContext");
Jason
AlexI
Thanks a lot Jason! I got it working.
hwolf
Is it necessary to have the classes or the jar file in the lib folder or is there another way for loading classes?
Here's my Scenario:
- I've got a RCP Plugin with a ScriptedDataSetEventAdapter.
- the ScriptedDataSetEventAdapter uses Classes of the Plugin an of other Plugins that are in the dependencies of the first
so I don't wan't to put the Class in the lib folder and I don't want to generate a jar...
I tried a cuple of things i found on this forum and on newsgroups...
--
WebappAccessor.start(ViewerPlugin.WEBAPP_CONTEXT, Activator.PLUGIN_ID, Path.EMPTY);
EngineConfig config = new EngineConfig();
HashMap hm = config.getAppContext();
hm.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ScriptedDataSetEH.class.getClassLoader());
config.setAppContext(hm);
--
all this doesn't work I've always got the following error:
--
28.01.2009 11:40:53 org.eclipse.birt.report.engine.script.internal.ScriptExecutor addException
WARNING: Die Klasse de.ScriptedDataSetEH wurde nicht gefunden.
Throwable occurred: org.eclipse.birt.report.engine.api.EngineException: Die Klasse de.ScriptedDataSetEH wurde nicht gefunden.
...
Caused by: java.lang.ClassNotFoundException: de.ScriptedDataSetEH
at org.eclipse.osgi.framework.internal.core.BundleLoader.findClassInternal(BundleLoader.java:481)
--
do i have a error in reasoning or have i missed something for loading or setting a resource in the report or something else?
Thanks for help
Holger
JasonW
Holger,
This code:
EngineConfig config = new EngineConfig();
HashMap hm = config.getAppContext();
hm.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, ScriptedDataSetEH.class.getClassLoader());
config.setAppContext(hm);
Is only used if you are using the RE API. The source code for the WebViewer plugin does similar code to this. Can you try modifying the plugin.xml for the WebViewer plugin and put a dependency in it on your used plugins. Then drop the jar with the event handler in the scriptlib directory?
Jason
JasonW
Holger,
I did some more experimenting with this scenario. You can get this to work following these instructions:
1 - Add the viewer plugin and the report engine plugins to your dependency list for your rcp plugin.
2 - Create your own appcontext class that sets the parent class loader:
package yourrcpplugin;
import java.util.Map;
import org.eclipse.birt.examples.rcpviewer.PreviewBirtAction;
import org.eclipse.birt.report.viewer.api.AppContextExtension;
import org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader;
public class MyAppContext extends AppContextExtension{
public Map getAppContext(Map appContext) {
Map hm = super.getAppContext(appContext);
hm.put("PARENT_CLASSLOADER", MyAppContext.class.getClassLoader());
return hm;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "MyAppContext";
}
}
you will notice I set the PARENT_CLASSLOADER to the current apps loader.
3 - add the app context extension to your plugin.xml
<extension
point="org.eclipse.birt.report.viewer.appcontext">
<appcontext
class="yourrcpplugin.MyAppContext">
</appcontext>
</extension>
4 - Implement your event handler in the plugin
That is why we put a dependency on the report engine plugin.
5 - Call the following code prior to running WebViewer.display();
ViewerPlugin.getDefault( ).getPluginPreferences( ).setValue("APPCONTEXT_EXTENSION_KEY", "MyAppContext");
WebViewer.display(reportName, browser, myparms);
HTH
Jason
hwolf
Hi Jason,<br />
<br />
thanks for your advice...<br />
<br />
I followed all your instructions but it doesn't work at all...<br />
<br />
I think it is a problem of my birt version, i'm using Rational 7.5 with Birt 2.3.0.v20080606 and I found this <a class='bbc_url' href='
http://webui.sourcelabs.com/eclipse/issues/239901'>[[BIRT]
BIRT-] Viewer Plugin Does not work with Scripted data Set</a> so i think my version of birt is to old...<br />
<br />
The problem with Rational is, that you can not update your plugins so easyly because of all the dependencies... (and because of eclipse 3.4.0 and birt need 3.4.1) so i think i must wait untill the next update from ibm<br />
<br />
<br />
If you or others have another idea or last hint be pleased to post<br />
<br />
Holger
JasonW
Holger,
I should have stated that this only works for BIRT 2.3.1 and above. This bug was fixed for this very reason. You may want to look at leaving the jar in the scriptlib directory and modifying the viewer plugins xml to add your other plugins to there dependecies list.
Jason