BIRT,render parameter form - tomcat7

I would like to integrate BIRT in a J2EE app. There is an excellent tutorial which explains the integration. To make a long story short, you need just to copy the libraries from "BIRT Runtime" into your EE project,write a servlet and a couple of classes to show the reports from your app.
To render the report you create IRenderTask instance and then invoke render() method.
IRenderTask iRenderTask= birtEngine.createRenderTask(reportDoc);
.....
iRenderTask.render();
But how can I render the form for the input parameters if the report requires them,only using BIRT API. For example, something like this:
ReportParams params = getParameters(reportDoc)
ReportParamsFormRenderTask rpf = new ReportParamsFormRenderTask(params)
rpf.render()
Thanks in advance.

We can get parameters informations through BIRT api with IGetParameterDefinitionTask.
However there is not a render feature for this, we need to walk in parameters list using this task and build an output with a JSP page, for example.
A more simple approach would be to display parameters values in a grid element at the beginning of birt reports, and use "visibility" property to hide/display this grid as we like, depending on a parameter value.

Thanks for the answer. I decide to go in easier way )).
I ended up with the deploying "BIRT Runtime Release Build" which you can download from link.I've put all the libraries from it into my EE app, in the web.xml I defined servlet-mapping of already implemented "ViewerServlet":
<servlet>
<servlet-name>ViewerServlet</servlet-name>
<servlet-class>org.eclipse.birt.report.servlet.ViewerServlet</servlet-class>
</servlet>
....
<servlet-mapping>
<servlet-name>ViewerServlet</servlet-name>
<url-pattern>/frameset</url-pattern>
</servlet-mapping>
and the other required mappings (all the same like in BIRT Runtime Release Build web-app example).
The only point I do not understand, why it uses axis. I can not run reports if I do not put "server-config.wsdd" file in my WEB-INF folder.

Related

What is the best way to read application-context.xml in Spring MVC application, Is it by adding in init-param tag or by adding in context-param tag?

In few applications I see application-context file being read via init-param and in few via context-param. My intention is to know which one to use when.
after all it dependence on you project requirement
1) if you want to set the access scope of data then use the .if you declare anything inside is only accessible only for that particular servlet. The init-param is declared inside the tag.
2) if you want to access the data whole application or anywhere in the application then you must go with
if you agree with this hit the up-arrow button

Parametric file inclusion in struts.xml configurations, based on properties

I have a web application (built on Spring, Struts 2) and I am trying to dynamically include a struts configuration file inside the main struts.xml configuration, based on a property.
Having defined, in the property file:
key=foo
I try to use it inside struts.xml:
<struts>
...
<include file="/config/struts/struts-${key}.xml" />
</struts>
To include the "struts-foo.xml" file (or another file, depending on the value).
The property file is loaded at startup by Spring, and I am able to use it inside Spring's xml files to parametrize bean definition.
You could leverage the Struts2 plugin framework.
You basically create a jar based project where you include all of a particular client's action mappings, support classes, etc. If you're also deploying into a Servlet 3.0 or higher container, you can also elect to include the UI artifacts inside the jar's META-INF\resources directory too for clean packaging.
Now, the contents you typically place inside the struts.xml for action mappings, you simply place inside struts-plugin.xml and place this xml file in the root of the jar file.
When the Struts2 framework starts, the jar files will be scanned, the struts-plugin.xml files will be picked up and automatically included in your application.
I use the same setup in conjunction with my maven build process so that if a client's deployment isn't suppose to include a specific feature or if a standard feature is to be customized, I can customize the action mappings from the stock ones.
In our case, the stock app is a struts-plugin based jar that gets loaded before any other jars and then subsequent feature jars are loaded to extend or override functionality. The actual WAR project has little inside it and is mainly an artifact used to deploy combinations of other project artifacts.
As you know you can change the struts.xml config file name, as below:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-config.xml</param-value>
</init-param>
</filter>
You can use this feature to change struts.xml dynamicly.
You need to extend the StrutsPrepareAndExecuteFilter and load your dynamic config here. Replace your new fildter with struts in web.xml.
public class MyStrutsPrepareAndExecuteFilter extends StrutsPrepareAndExecuteFilter{
#Override
protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
//load your config here
}
}
Please have a look at StrutsPrepareAndExecuteFilter source code. you can see how the config is loaded and you can how you can change it.
If you want to only dynamical change your application messages you can do it more easily by just calling LocalizedTextUtil.addDefaultResourceBundle ("messages/customize") in MyStrutsPrepareAndExecuteFilter

How to make an AJAX call in Magnolia Blossom?

I am new to Magnolia Blossom.
I have to perform an AJAX call in my application in Blossom.
We have a Controller per component. So I am unable to make an AJAX request.
Can anyone suggest how can I achieve this?
you may define a different Servlet (and web application context), you can define a servlet that handles all the requests that start for /rest/* and then below that on your web.xml you can define the blossom servlet.
All the rest is configuration, try to see how to create a webapp with 2 different contexts.
The controllers you're using for rendering content are not accessible to requests coming in to the servlet container. Without content they're pretty useless and won't generate meaningful output. You need a separate DispatcherServlet handling these AJAX requests.
There's two ways to achieve this. You can either add a new DispatcherServlet to web.xml or you can add a servlet to your module that is installed when your module is installed.
The latter is the better choice because you won't need to have two separate ApplicationContexts. The one created in your module on startup will be the parent of both DispatcherServlets so both can access beans within it. You also won't need to update web.xml which makes module install easier and upgrades of Magnolia easier.
In your module descriptor add this snippet:
<servlets>
<servlet>
<name>dispatcher</name>
<class>org.springframework.web.servlet.DispatcherServlet</class>
<mappings>
<mapping>/ajax/*</mapping>
</mappings>
<params>
<param>
<name>contextConfigLocation</name>
<value>classpath:/ajax-servlet.xml</value>
</param>
</params>
</servlet>
</servlets>
This, and other topics, is described in the Magnolia wiki https://wiki.magnolia-cms.com/display/WIKI/Adding+a+DispatcherServlet+to+a+Blossom+module
Depending on what you want to get out, you can also use REST module of Magnolia. To e.g. read a title of website you can just call http://localhost:8080/magnoliaAuthor/.rest/properties/v1/website/demo-project/siteTitle more details at documentation
And you can use REST module to also very easily add your own endpoints by just annotating source code.
HTH,
Jan

Can <security-constraint> tag in web.xml be dynamically generated or written outside web.xml?

I met a problem, I want to set the tag of security-constraint according to my configuration file dynamically, but I can't do it. So I hope tag in web.xml can be dynamically generated or written outside web.xml. Thanks a lot for your help!
I think your question could be related to this one. However, if you were working with Servlet 3.0 spec, you could try the approach of programmatically adding and configuring security for the servlet, as shown here.

integrating BIRT run time in existing Java EE application

I am newbie in BIRT reporting. I am trying to integrate BIRT runtime as per solution given in this post here but it did not work. I also tried to find BirtEngineServlet from org.eclipse.birt.runtime_3.7.1.v20110913-1734.jar file but I could not find this class.
Can anybody please help me out?
2 hours later:
Ok so BirtEngineServlet is in viewservlets.jar file, it resides in:
birt-runtime-3_7_1\WebViewerExample\WEB-INF\lib.
Because BirtEngineServlet is found in viewServlets.jar and this jar is located under path I mentioned, I tried to copy all jars from above path into my application WEB-INF/lib folder and tried to access the test report by using URL suggested in linked post .The URL I used is: localhost:8080/myOwnWebapp/…. Now I am getting following exception:
File "/webcontent/birt/pages/layout/RequesterFragment.jsp" not found at
org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:412) at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
my web.xml has following code.
<servlet>
<servlet-name>EngineServlet</servlet-name>
<servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EngineServlet</servlet-name>
<url-pattern>/output</url-pattern>
</servlet-mapping>
As per today you can easily integrate BIRT like any other API as maven dependency into existing Java EE applications.
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.4.1</version>
</dependency>
Follow the Integrating Birt tutorial for coding details.

Resources