Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Custom table handler and JSF
Custom table handler and JSF [message #628923] Fri, 24 September 2010 17:55 Go to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Hi,

I have a JSF 1.2 and I invoke my report from managed bean. My report contains custom handler:

public class MyTableHandler extends TableEventAdapter {
  
   public void onCreate(ITableInstance table, IReportContext   reportContext) {
   }

   public void onPrepare(ITable table, IReportContext reportContext) {
   }

   public void onRender(ITableInstance table, IReportContext reportContext) {
   }
}


My question is : what is the best way to pass any object from managed bean (in my example there is a List<Employees> ) and get it in onCreate() method ? Is there any way to set this object to IReportContext ?

Kuba
Re: Custom table handler and JSF [message #628928 is a reply to message #628923] Fri, 24 September 2010 18:34 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Kuba,

Are you using the RE API? If so you could call
task.getAppContext().put("myobject", employeeobject);

Then in the table handler

reportContext.getAppContext().get("myobject");

Jason

On 9/24/2010 1:55 PM, Kuba P. wrote:
> Hi,
>
> I have a JSF 1.2 and I invoke my report from managed bean. My report
> contains custom handler:
>
>
> public class MyTableHandler extends TableEventAdapter {
>
> public void onCreate(ITableInstance table, IReportContext reportContext) {
> }
>
> public void onPrepare(ITable table, IReportContext reportContext) {
> }
>
> public void onRender(ITableInstance table, IReportContext reportContext) {
> }
> }
>
> My question is : what is the best way to pass any object from managed
> bean (in my example there is a List<Employees> ) and get it in
> onCreate() method ? Is there any way to set this object to IReportContext ?
>
> Kuba
Re: Custom table handler and JSF [message #628936 is a reply to message #628928] Fri, 24 September 2010 19:33 Go to previous messageGo to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Hi,

Thanks for fast replay. I have a birt viewer included in my JSF application. What is "task" object and how can I get in my managed bean ? Dou you have some more code ?

Kuba

[Updated on: Fri, 24 September 2010 19:34]

Report message to a moderator

Re: Custom table handler and JSF [message #628939 is a reply to message #628936] Fri, 24 September 2010 19:55 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Kuba,

task is the engine task used to run the report. I thought you were
using the RE API. If you are looking at the viewer have a look at this
page:
http://wiki.eclipse.org/Adding_an_Object_to_the_Application_ Context_for_the_Viewer_%28BIRT%29

Jason

On 9/24/2010 3:33 PM, Kuba P. wrote:
> Hi,
>
> Thanks got fast replay. I have a birt viewer included in my JSF
> application. What is "task" object and how can I get in my managed bean
> ? Dou you have some more code ?
>
> Kuba
Re: Custom table handler and JSF [message #628978 is a reply to message #628923] Sat, 25 September 2010 09:18 Go to previous messageGo to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Hi,

Solution you are refered is the same as I have currently. I set my variables to session in managed bean and get in my table handler inside onCreate() method. But I'm curious is there any method to pass my objects to scope shorter than session. e.g. request. I don't need longer life of these objects then report invocation.
Re: Custom table handler and JSF [message #629251 is a reply to message #628978] Mon, 27 September 2010 15:26 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You can always get the request object in script.
reportContext.getHttpServletRequest().getAttribute("myattribute ");

Jason

On 9/25/2010 5:18 AM, Kuba P. wrote:
> Hi,
>
> Solution you are refered is the same as I have currently. I set my
> variables to session in managed bean and get in my table handler inside
> onCreate() method. But I'm curious is there any method to pass my
> objects to scope shorter than session. e.g. request. I don't need longer
> life of these objects then report invocation.
>
Re: Custom table handler and JSF [message #629331 is a reply to message #629251] Mon, 27 September 2010 19:54 Go to previous messageGo to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Hi,

I think this is solution I was looking for. Thanks for response - I'll try that.
Re: Custom table handler and JSF [message #629442 is a reply to message #629251] Tue, 28 September 2010 10:14 Go to previous messageGo to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Hi,

this is my manged bean code

public class PageBean implements Serializable{
	
	private List<Employee> emp;
	
	@SuppressWarnings("unused")
	@PostConstruct
	private void init(){
		
		emp = EmployeeDAO.getEmployees();
	}

	public void runReport(ActionEvent evt){
		
		String url = "/frameset?__report=WEB-INF/birt/DemoReport.rptdesign&__fittopage=true";
		
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletRequest  req  = (HttpServletRequest) context.getExternalContext().getRequest();
		HttpServletResponse resp = (HttpServletResponse)context.getExternalContext().getResponse();
		
		req.setAttribute("AppContextKey", "EmpList");
		req.setAttribute("AppContextValue", emp);
		
		try {
			req.getRequestDispatcher(url).forward(req, resp);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

and this is my event handler class for Scripted Data Source
public class EmployeesTableHandler extends ScriptedDataSetEventAdapter {
	
	private List<Employee> employees;
	private int rows = 0;
	
	@SuppressWarnings("unchecked")
	@Override
	public void beforeOpen(IDataSetInstance dataSet, IReportContext ctx){
		
		employees = (List<Employee>)ctx.getAppContext().get("EmpList");
	}
	
	@Override
	public boolean fetch(IDataSetInstance dataSet, IUpdatableDataSetRow row) {
		
		try {
			if(rows == employees.size()){
				return false;
			}
		
			Employee emp = employees.get(rows);
			
			row.setColumnValue("FirstName", emp.getFirstName());
			row.setColumnValue("LastName",  emp.getLastName());
			row.setColumnValue("Age",       emp.getAge());
			
			rows++;
			
			return true;
			
		} catch (ScriptException e) {
			e.printStackTrace();
			return false;
		}
	}
}

But
ctx.getAppContext().get("EmpList")
returns null for me

Folowing code works as expected
	public void beforeOpen(IDataSetInstance dataSet, IReportContext ctx){
		
		employees = EmployeeDAO.getEmployees();
	}


So, the problem is with requested params.

Kuba

[Updated on: Tue, 28 September 2010 10:19]

Report message to a moderator

Re: Custom table handler and JSF [message #629447 is a reply to message #629442] Tue, 28 September 2010 10:33 Go to previous messageGo to next message
Kuba P. is currently offline Kuba P.Friend
Messages: 9
Registered: February 2010
Junior Member
Interested - when I used sesson instead of request
HttpSession session = (HttpSession)context.getExternalContext().getSession(false);
		
session.setAttribute("AppContextKey", "EmpList");
session.setAttribute("AppContextValue", emp);


everything works. Why request scope is not visible in my table handler ?

Kuba
Re: Custom table handler and JSF [message #629778 is a reply to message #629447] Wed, 29 September 2010 14:24 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Kuba,

As a test could you change your url
/frameset to /preivew and try the request object again?

Jason

On 9/28/2010 6:33 AM, Kuba P. wrote:
> Interested - when I used sesson instead of request
>
> HttpSession session =
> (HttpSession)context.getExternalContext().getSession(false);
>
> session.setAttribute("AppContextKey", "EmpList");
> session.setAttribute("AppContextValue", emp);
>
>
> everything works. Why request scope is not visible in my table handler ?
>
> Kuba
Previous Topic:Report Engine Javadoc
Next Topic:BIRT Servlet embed report in some jsp
Goto Forum:
  


Current Time: Tue Mar 19 02:46:41 GMT 2024

Powered by FUDForum. Page generated in 0.02805 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top