|
Re: Custom table handler and JSF [message #628928 is a reply to message #628923] |
Fri, 24 September 2010 18:34 |
|
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 #629251 is a reply to message #628978] |
Mon, 27 September 2010 15:26 |
|
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 #629442 is a reply to message #629251] |
Tue, 28 September 2010 10:14 |
Kuba P. 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 #629778 is a reply to message #629447] |
Wed, 29 September 2010 14:24 |
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04137 seconds