站内搜索

返回   安讯中国 > 安讯产品 > 百灵报表(BIRT)
注册
忘记密码?
论坛帮助 日历事件 搜索 今日新帖 标记版面已读

回复
 
LinkBack 主题工具 搜索本主题 显示模式
  #1 (permalink)  
旧 2008-7-9, 05:59 PM
Junior Member
 
注册日期: 2008-6-26
帖子: 13
存款: 143
默认 自定义Engine 出现的问题

我自己定义的 engine, rptdesign使用了Script数据源
出现了下面的错误

The following items have errors:


ReportDesign (id = 1):
- There are errors evaluating script "count = 0;
cf = new Packages.birt.StudentListFactory();
c = cf.createStuList();":{1}.
Error.ScriptEvaluationError ( 1 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "count = 0;cf = new Packages.birt.StudentListFactory();c = cf.createStuList();":{1}. at

+ There are errors evaluating script "if (count < c.length){
row["sid"] = c[count].getSid();
row["sname"] = c[count].getSname();
row["sage"] = c[count].getSage();
row["gid"] = c[count].getGid();
count++;
return true;
}
return false;":{1}.
Error.ScriptEvaluationError ( 1 time(s) )
detail : org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "if (count < c.length){ row["sid"] = c[count].getSid(); row["sname"] = c[count].getSname(); row["sage"] = c[count].getSage(); row["gid"] = c[count].getGid(); count++; return true;}return false;":{1}. at

+ Unhandled exception when executing script
回复时引用此帖
  #2 (permalink)  
旧 2008-7-10, 09:07 AM
Junior Member
 
注册日期: 2008-6-26
帖子: 13
存款: 143
默认 BirtEngine 的代码实现

public class BirtEngine {

IReportEngine birtEngine;
public IReportEngine getBireEngin(ServletContext sc) {
EngineConfig config = new EngineConfig();
config.setLogConfig(sc.getRealPath(""), Level.FINE);

config.setEngineHome("");
IPlatformContext context = new PlatformServletContext(sc);
config.setPlatformContext(context);

// // Register new image handler 解决了读取图片时的路径问题
// HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig();
// emitterConfig.setActionHandler(new HTMLActionHandler());
// HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
// emitterConfig.setImageHandler(imageHandler);
// config.getEmitterConfigs().put("html", emitterConfig); // -NLS-1$

try {
Platform.startup(config);
} catch (BirtException e) {
e.printStackTrace();
}

IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
birtEngine = factory.createReportEngine(config);
return birtEngine;

}
回复时引用此帖
  #3 (permalink)  
旧 2008-7-10, 09:09 AM
Junior Member
 
注册日期: 2008-6-26
帖子: 13
存款: 143
默认 action中报表的实现

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws ServletException {
// TODO Auto-generated method stub
HashMap paramDetails = new HashMap();

BirtEngine birtReportEngine = new BirtEngine();
IReportEngine engine = birtReportEngine.getBireEngin(request.getSession().getServletContext());

// setup image directory
HTMLRenderContext renderContext = new HTMLRenderContext();
renderContext.setBaseImageURL(request.getContextPath() + "/report/images");
renderContext.setImageDirectory(request.getSession().getServletContext().getRealPath("/report/images"));

// logger.log(Level.FINE, "image directory "
// + sc.getRealPath("/report/images"));
System.out.println(renderContext.getBaseImageURL());
System.out.println(renderContext.getImageDirectory());
HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();
contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT, renderContext);
IReportRunnable design;
try {
// Open report design
design = engine.openReportDesign(request.getSession().getServletContext().getRealPath("/reports")
+ "/stuparam.rptdesign");

// 以下是将报表里的参数和传递进来的参数匹配然后放到parmDetails集合中
IGetParameterDefinitionTask taskParam = engine.createGetParameterDefinitionTask(design);
Collection params = taskParam.getParameterDefns(true);
Iterator iter = params.iterator();
// // Iterator iterList = paramsList.iterator();
// // Iterate over all parameters
while (iter.hasNext()) {
IParameterDefnBase param = (IParameterDefnBase) iter.next();
// // Parameters are not in a group
IScalarParameterDefn scalar = (IScalarParameterDefn) param;
if (scalar.getName().equals("age")) {

// // String paramList = (String)iterList.next();
paramDetails.put(scalar.getName(), 22);
// // System.out.println(scalar.getName() + " " +
// paramList);
}
// else {
// Date paramList = new Date();
// try {
// // paramList =
// // DateUtil.parse((String)iterList.next(),"yyyy-M-d");
// } catch (Exception e) {
// e.printStackTrace();
// }
// // parmDetails.put(scalar.getName(), paramList);
// // System.out.println(scalar.getName() + " " + paramList);
// }
}
// taskParam.close();
//

// create task to run and render report
IRunAndRenderTask task = engine.createRunAndRenderTask(design);
task.setAppContext(contextMap);
task.setParameterValues(paramDetails);

// set output options
HTMLRenderOption options = new HTMLRenderOption();
options.setOutputFormat(HTMLRenderOption.LAYOUT_PREFERENCE_AUTO);
options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);
options.setOutputStream(response.getOutputStream());
task.setRenderOption(options);

// run report
task.run();
task.close();
} catch (Exception e) {

e.printStackTrace();
throw new ServletException(e);
}

return null;
回复时引用此帖
  #4 (permalink)  
旧 2008-7-10, 09:36 AM
Member
 
注册日期: 2008-5-22
帖子: 79
存款: 337
默认

birt.StudentListFactory放在什么目录? 需要在EngineConfig中的AppContext中需要定义用户自己的appClassLoader,BIRT使用此ClassLoader装载在script中应用到的Class.
HashMap appContext = new HashMap();
appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader);
config.setAppContext(appContext);
回复时引用此帖
  #5 (permalink)  
旧 2008-7-10, 09:50 AM
Junior Member
 
注册日期: 2008-6-26
帖子: 13
存款: 143
默认

引用:
作者: greatyan 查看帖子
birt.StudentListFactory放在什么目录? 需要在EngineConfig中的AppContext中需要定义用户自己的appClassLoader,BIRT使用此ClassLoader装载在script中应用到的Class.
HashMap appContext = new HashMap();
appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader);
config.setAppContext(appContext);
高手,自定义 是否还需要 birt-runtime引入工程?如果不需要我需要引入哪些jar包啊?
谢谢啦!
回复时引用此帖
  #6 (permalink)  
旧 2008-7-10, 10:36 AM
Member
 
注册日期: 2008-5-22
帖子: 79
存款: 337
默认

在Eclips中, 需要在某个Project中使用BIRT时, 为了让使用BIRT API编译通过, 需要将BIRT的lib加入project的classpath中. BIRT的LIB文件安装在 /birt-runtime/report engine/lib目录下.

如果将该项目发布到运行环境中,这些JAR文件同样需要安装到运行环境的classpath中. 如果是WAR/EAR应用,需要将LIB发布到/web-inf/lib目录下.
回复时引用此帖
  #7 (permalink)  
旧 2008-7-10, 02:04 PM
Junior Member
 
注册日期: 2008-6-26
帖子: 13
存款: 143
默认

引用:
作者: greatyan 查看帖子
birt.StudentListFactory放在什么目录? 需要在EngineConfig中的AppContext中需要定义用户自己的appClassLoader,BIRT使用此ClassLoader装载在script中应用到的Class.
HashMap appContext = new HashMap();
appContext.put(EngineConstants.APPCONTEXT_CLASSLOADER_KEY, classLoader);
config.setAppContext(appContext);
你好,我还有个问题,是不是我要将所用birt报表中的bean,都放在 appcontent中,那我自定义的 birtEngine用不用放进去, 还有 EngineConstants.APPCONTEXT_CLASSLOADER_KEY 这个枚举都是什么含义,能否说明一下?谢谢!
你真是 安讯的活雷锋。
回复时引用此帖
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

论坛启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用


服务条款 | 隐私政策
安讯中国 上海浦东新区浦东南路1271号华融大厦21层2101室
电话:(+86)21-58826388   发送邮件联系我们  沪ICP备06010344号
Actuate Corporation © 2008
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

Content Relevant URLs by vBSEO 3.1.0