Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Programatically adding a sort condition to a table
Edd
Hi,<br />
<br />
I am attempting to write some script that simplifies table sorting and have been getting quite close but am now wondering if I have found a bug...or have just misunderstood limitations.<br />
<br />
So my relevant code:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var reportRunnable = reportContext.getReportRunnable();
var reportDesign = reportRunnable.getDesignInstance();
var table = reportDesign.getTable(tableName);
var sortCondition = org.eclipse.birt.report.engine.api.script.element.StructureScriptAPIFactory.createSortCondition();
sortCondition.setKey("row["" + columnKey + ""]");
sortCondition.setDirection("desc");
table.removeSortConditions();
table.addSortCondition(sortCondition);
</pre>
<br />
I am getting a NullPointerException on line 164 in the class Listing:<br />
org.eclipse.birt.report.engine.script.internal.element.Listing, in the method removeSortConditions...<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
( (org.eclipse.birt.report.model.api.simpleapi.IListing) designElementImpl ).removeSortConditions();
</pre>
<br />
So the above implies 'designElementImpl' is null, having looked further at the source it seemed to imply that to instantiate the 'table' object, the following constructor was used:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public Table( TableHandle table );
</pre>
<br />
And moving up the heirarchy of super classes, it implies that the in the constructor of DesignElement, the following is returning null:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
designElementImpl = SimpleElementFactory.getInstance( ).getElement(handle);
</pre>
<br />
Any one any thoughts? Am I just not able to what I am trying to do?<br />
<br />
Thanks in advance.<br />
<br />
Edit: Am using BIRT 2.5.1
Find more posts tagged with
Comments
mwilliams
Hi Edd,
Where are you placing your script?
Edd
I'm placing the JS within the 'initialize' option (for the whole report) but have tried most, if not all, others...any ideas?<br />
<br />
If it helps, the full stack trace is:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
Error.UnhandledScriptError ( 1 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: Unhandled exception when executing script.
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.addException(ScriptExecutor.java:162)
at org.eclipse.birt.report.engine.script.internal.ReportScriptExecutor.handleInitialize(ReportScriptExecutor.java:51)
at org.eclipse.birt.report.engine.api.impl.EngineTask.loadDesign(EngineTask.java:1582)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:95)
at org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:75)
at org.eclipse.birt.report.service.ReportEngineService.runAndRenderReport(ReportEngineService.java:882)
at org.eclipse.birt.report.service.BirtViewerReportService.runAndRenderReport(BirtViewerReportService.java:973)
at org.eclipse.birt.report.service.actionhandler.BirtGetPageAllActionHandler.__execute(BirtGetPageAllActionHandler.java:131)
at org.eclipse.birt.report.service.actionhandler.AbstractBaseActionHandler.execute(AbstractBaseActionHandler.java:90)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseDocumentProcessor.__executeAction(AbstractBaseDocumentProcessor.java:47)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.executeAction(AbstractBaseComponentProcessor.java:143)
at org.eclipse.birt.report.soapengine.processor.BirtDocumentProcessor.handleGetPageAll(BirtDocumentProcessor.java:183)
at sun.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.birt.report.soapengine.processor.AbstractBaseComponentProcessor.process(AbstractBaseComponentProcessor.java:112)
at org.eclipse.birt.report.soapengine.endpoint.BirtSoapBindingImpl.getUpdatedObjects(BirtSoapBindingImpl.java:66)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.doPost(BirtSoapMessageDispatcherServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.birt.report.servlet.BirtSoapMessageDispatcherServlet.service(BirtSoapMessageDispatcherServlet.java:122)
at org.eclipse.equinox.http.registry.internal.ServletManager$ServletWrapper.service(ServletManager.java:180)
at org.eclipse.equinox.http.servlet.internal.ServletRegistration.handleRequest(ServletRegistration.java:90)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:111)
at org.eclipse.equinox.http.servlet.internal.ProxyServlet.service(ProxyServlet.java:59)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.eclipse.equinox.http.jetty.internal.HttpServerManager$InternalHttpServiceServlet.service(HttpServerManager.java:318)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:380)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:748)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:213)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
Caused by: org.mozilla.javascript.WrappedException: Wrapped java.lang.NullPointerException (/report/method[
@name="
;initialize"]#37)
at org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1654)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:175)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:243)
at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:119)
at org.mozilla.javascript.gen.c471._c0(/report/method[
@name="
;initialize"]:37)
at org.mozilla.javascript.gen.c471.call(/report/method[
@name="
;initialize"])
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
at org.mozilla.javascript.gen.c471.call(/report/method[
@name="
;initialize"])
at org.mozilla.javascript.gen.c471.exec(/report/method[
@name="
;initialize"])
at org.eclipse.birt.report.engine.javascript.JavascriptEngine.evaluate(JavascriptEngine.java:256)
at org.eclipse.birt.core.script.ScriptContext.evaluate(ScriptContext.java:152)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:706)
at org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:637)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScriptInternal(ScriptExecutor.java:61)
at org.eclipse.birt.report.engine.script.internal.ScriptExecutor.handleScript(ScriptExecutor.java:48)
at org.eclipse.birt.report.engine.script.internal.ReportScriptExecutor.handleInitialize(ReportScriptExecutor.java:43)
... 51 more
Caused by: java.lang.NullPointerException
at org.eclipse.birt.report.engine.script.internal.element.Listing.removeSortConditions(Listing.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:160)
... 66 more
</pre>
<br />
Cheers.
mwilliams
Edd,
I tried this in my initialize and beforeFactory methods and they both work as expected with no error. I don't have a sort condition on the table to start with though. Are you starting with a sort condition on the table? Let me know.
Edd
I have had in the past but not anymore...will double check that the XML doesn't have any record of the sort condition. Are we using the same version as well - 2.5.1?
Thanks
johnw
<a class='bbc_url' href='
http://digiassn.blogspot.com/2007/05/birt-strong-suit-is-in-realm-of-online.html'>The
Digital Voice: BIRT: Resort Columns After Report Has Been Run</a><br />
<br />
Follow along the comments. The original post showed adding a sort condition in BIRT 2.2. They changed the scripting model in 2.3, so the updated script is in the comments.
mwilliams
Edd,<br />
<br />
Yes, I used 2.5.1 as well. I had a simple query that brought in customer number and credit limit. Dropped the dataSet into the layout to create the table, named it myTable and put the following in my beforeFactory:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var reportRunnable = reportContext.getReportRunnable();
var reportDesign = reportRunnable.getDesignInstance();
var table = reportDesign.getTable("myTable");
var sortCondition = org.eclipse.birt.report.engine.api.script.element.StructureScriptAPIFactory.createSortCondition();
sortCondition.setKey("row["" + "CREDITLIMIT" + ""]");
sortCondition.setDirection("desc");
table.removeSortConditions();
table.addSortCondition(sortCondition);
</pre>
<br />
Previewed and it sorted the table by credit limit in descending order. I had not previous sort condition on the table that was being removed though.
Edd
Thanks for all your help...and it's kinda working now, in that I started again!
I created a new report and copied my datasource and dataset into it. Then copied some client side JS and the server-side script that I posted and now I can click on table headers and successfully sort.
I'm not excatly sure what's wrong with my other report though because that's still throwing the same NPE. Possibly it's related to me using a report template and library? The new report is very basic, has no theme, or any libraries, and is based on the blank template...
I will continue to look into it when I have more time, but thanks again.
mwilliams
Hi Edd,<br />
<br />
You may try rebuilding using the library items in 2.5.1 and you also may try 2.5.2, which was just released, as it may be something that has been noticed/reported and fixed. If it doesn't work in either, please log a bug report for the NPE issue when using the library at <a class='bbc_url' href='
http://www.birt-exchange.org/bug-reporting/'>Report
Bugs - BIRT Exchange</a>. Thanks.