BIRT Exchange Forum: use Spring beans inside a BIRT report - BIRT Exchange Forum

Jump to content


 

BIRT Poll: To best make a table fill a pdf page before breaking (PL=page layout, PBI=page break interval) set:

PL: auto, PBI: 0PL: fixed, PBI: 0PL: auto, PBI: 1000000PL: fixed, PBI: 1000000
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

use Spring beans inside a BIRT report Rate Topic: -----

#1 User is offline   EmaAlina Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 23-May 12


Posted 23 May 2012 - 06:11 AM

Hi guys,
I have a problem related to the BIRT reports.

The problem is that my application uses spring, and the objects can
not be instantiated directly. Instead they have to be accessed through the
web application context like -

///////////////////////////////////////////////
WebApplicationContext wapp =
WebApplicationContextUtils.getRequiredWebApplicationContext(getServletConfig().servletContext());
return wapp .getBean(name);
///////////////////////////////////////////////

If I could get servletContext somehow in BIRT, this could be used.
However, I could not find the way to do this and I would need to find a way to access it from the BIRT report.

If you have any ideas, please let me know.
0

#2 User is offline   JasonW Icon

  • Senior Member
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 2505
  • Joined: 08-August 07


Posted 23 May 2012 - 06:25 AM

You can get the servlet context in script like:

reportContext.getHttpServletRequest().getSession().getServletContext()

BTW have you read this article?
http://www.springsou...thSpringAndBIRT

Jason
0

#3 User is offline   EmaAlina Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 23-May 12


Posted 23 May 2012 - 07:02 AM

Hi Jason,

I have read the article and I try to use the information from it in my Birt repot but when I call the method getSession() I receive an error as : "Cannot call method "getSession" of null".

Below is the code that I added in the report :

<method name="initialize"><!<CDATA[
importPackage(Packages.org.springframework.web.context);
importPackage(Packages.org.springframework.context);
importPackage(Packages.org.springframework.web.context.support);

var sc = reportContext.getHttpServletRequest().getSession().getServletContext();
springWebAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
var service = springWebAppContext.getBean("myBean");

]]></method>

Is there something wrong?

Thank you for the help,

Ema
0

#4 User is offline   JasonW Icon

  • Senior Member
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 2505
  • Joined: 08-August 07


Posted 23 May 2012 - 12:58 PM

How are you running BIRT? Are you using the BIRT Viewer?

Jason
0

#5 User is offline   EmaAlina Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 23-May 12


Posted 23 May 2012 - 10:46 PM

View PostJasonW, on 23 May 2012 - 01:58 PM, said:

How are you running BIRT? Are you using the BIRT Viewer?

Jason

Hi Jason,

I run the Birt in a web application using the web server Tomcat 5.5.
So, I have a Spring bean in my webapp, in WEB-INF/MyConfig folder. I would need to find a way to access it from the BIRT report.

Thank you for the help,

Ema
0

#6 User is offline   EmaAlina Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 5
  • Joined: 23-May 12


Posted 24 May 2012 - 07:06 AM

Hi Jason,

I don’t have the HttpServletRequest object available within a deployed report.The IReportContext has the method getHttpSerlvetRequest() but for me that always returns null. Is this a bug of the BIRT report?
How can I fix that bug?

Thanks,
Ema
0

#7 User is offline   JasonW Icon

  • Senior Member
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 2505
  • Joined: 08-August 07


Posted 24 May 2012 - 08:54 AM

No this is not a bug. If you are using the engine you have to load the request object into the appcontext. The Birt Viewer does this by using something similar to:

//task like run or render
task.getAppContext().put(EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, yourrequestobject);

Jason
0

#8 User is offline   vartika Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 9
  • Joined: 11-July 12


Posted 16 July 2012 - 05:04 AM

Hi Jason,

I am using IRenderOption and even after setting this
iRenderTask.getAppContext().put( EngineConstants.APPCONTEXT_BIRT_VIEWER_HTTPSERVET_REQUEST, request )
I am getting error TypeError: Cannot call method "getSession" of null.

If you have any idea please let me know.


Vartika
0

#9 User is offline   JasonW Icon

  • Senior Member
  • Icon
  • View blog
  • Group: Administrators
  • Posts: 2505
  • Joined: 08-August 07


Posted 16 July 2012 - 07:15 PM

Generally that command is entered on a run task not a render task. Where are you calling the getSession?

Jason
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users