|
Re: createParamBinding fails when attached to a TextDataHandle [message #367384 is a reply to message #367361] |
Mon, 09 March 2009 22:13 |
Eclipse User |
|
|
|
Originally posted by: jasonweathersby.alltel.net
Malte,
Try something like the following.
Note that I am setting up bound columns much like you would do on a table.
Jason
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.model.api.CellHandle;
import org.eclipse.birt.report.model.api.ColumnHandle;
import org.eclipse.birt.report.model.api.DataItemHandle;
import org.eclipse.birt.report.model.api.DataSetHandle;
import org.eclipse.birt.report.model.api.DesignConfig;
import org.eclipse.birt.report.model.api.ElementFactory;
import org.eclipse.birt.report.model.api.IDesignEngine;
import org.eclipse.birt.report.model.api.IDesignEngineFactory;
import org.eclipse.birt.report.model.api.LabelHandle;
import org.eclipse.birt.report.model.api.ImageHandle;
import org.eclipse.birt.report.model.api.ActionHandle;
import org.eclipse.birt.report.model.api.ReportElementHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;
import org.eclipse.birt.report.model.api.TextDataHandle;
import org.eclipse.birt.report.model.elements.JointDataSet;
import org.eclipse.birt.report.model.api.OdaDataSetHandle;
import org.eclipse.birt.report.model.api.JointDataSetHandle;
import org.eclipse.birt.report.model.api.JoinConditionHandle;
import org.eclipse.birt.report.model.api.OdaDataSourceHandle;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.RowHandle;
import org.eclipse.birt.report.model.api.SessionHandle;
import org.eclipse.birt.report.model.api.StructureFactory;
import org.eclipse.birt.report.model.api.TableHandle;
import org.eclipse.birt.report.model.api.activity.SemanticException ;
import org.eclipse.birt.report.model.api.elements.structures.Comput edColumn;
import org.eclipse.birt.report.model.api.PropertyHandle;
import org.eclipse.birt.report.model.elements.ReportItem;
import org.eclipse.birt.report.model.api.elements.structures.Embedd edImage;
import org.eclipse.birt.report.model.elements.Style;
import org.eclipse.birt.report.model.elements.ReportDesign;
import org.eclipse.birt.report.model.api.StyleHandle;
import
org.eclipse.birt.report.model.api.elements.structures.Aggreg ationArgument;
import
org.eclipse.birt.report.model.api.elements.structures.DataSe tParameter;
import org.eclipse.birt.report.model.api.elements.structures.MapRul e;
import org.eclipse.birt.report.model.api.elements.structures.HideRu le;
import
org.eclipse.birt.report.model.api.elements.structures.OdaDat aSetParameter;
import
org.eclipse.birt.report.model.api.elements.structures.Proper tyBinding;
import org.eclipse.birt.report.model.api.elements.structures.TOC;
import org.eclipse.birt.report.model.api.elements.structures.JoinCo ndition;
import org.eclipse.birt.report.model.api.elements.structures.ParamB inding;
import org.eclipse.birt.report.model.api.elements.DesignChoiceConst ants;
import org.eclipse.birt.report.model.api.elements.structures.Highli ghtRule;
import org.eclipse.birt.report.model.elements.interfaces.IJointData SetModel;
import org.eclipse.birt.report.model.api.elements.structures.SortKe y;
import org.eclipse.birt.report.model.api.SortKeyHandle;
import
org.eclipse.birt.report.model.api.elements.structures.Filter Condition;
import org.eclipse.birt.report.model.api.elements.structures.Action ;
import org.eclipse.birt.report.model.api.elements.structures.Includ eScript;
import java.util.Iterator;
import com.ibm.icu.util.ULocale;
/**
* Simple BIRT Design Engine API (DEAPI) demo.
*/
public class StructFactoryTestDsParm
{
ReportDesignHandle designHandle = null;
ElementFactory designFactory = null;
StructureFactory structFactory = null;
public static void main( String[] args )
{
try
{
StructFactoryTestDsParm de = new StructFactoryTestDsParm();
de.buildReport();
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
void buildDataSource( ) throws SemanticException
{
OdaDataSourceHandle dsHandle = designFactory.newOdaDataSource(
"Data Source", "org.eclipse.birt.report.data.oda.jdbc" );
dsHandle.setProperty( "odaDriverClass",
"org.eclipse.birt.report.data.oda.sampledb.Driver" );
dsHandle.setProperty( "odaURL", "jdbc:classicmodels:sampledb" );
dsHandle.setProperty( "odaUser", "ClassicModels" );
dsHandle.setProperty( "odaPassword", "" );
PropertyBinding pb = new PropertyBinding();
designHandle.getDataSources( ).add( dsHandle );
}
void buildDataSet2( ) throws SemanticException
{
OdaDataSetHandle dsHandle = designFactory.newOdaDataSet( "ds2",
"org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet" );
dsHandle.setDataSource( "Data Source" );
String qry = "Select * from orderdetails where ordernumber = ?";
dsHandle.setQueryText( qry );
designHandle.getDataSets( ).add( dsHandle );
OdaDataSetParameter parameter =
StructureFactory.createOdaDataSetParameter();
parameter.setName( "param1" );
parameter.setPosition(1);
parameter.setDataType("integer");
parameter.setAllowNull(true);
parameter.setDefaultValue("10105");
parameter.setIsOptional(false);
parameter.setIsOutput(false);
parameter.setIsInput(true);
PropertyHandle parameterHandle = dsHandle.getPropertyHandle(
DataSetHandle.PARAMETERS_PROP );
parameterHandle.addItem( parameter );
}
void buildReport() throws IOException, SemanticException
{
DesignConfig config = new DesignConfig( );
config.setBIRTHome("C:/birt/birt-runtime-2_3_1/birt-runtime-2_3_1/ReportEngine ");
IDesignEngine engine = null;
try{
Platform.startup( config );
IDesignEngineFactory factory = (IDesignEngineFactory) Platform
.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );
engine = factory.createDesignEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}
SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;
ReportDesignHandle design = null;
try{
//open a design or a template
designHandle = session.createDesign();
designFactory = designHandle.getElementFactory( );
buildDataSource();
buildDataSet2();
TextDataHandle tdh = designHandle.getElementFactory(
).newTextData("MyText" ); //$NON-NLS-1$
tdh.setValueExpr("row[\"ordernum\"] + \"---\" + row[\"productcode\"];");
designHandle.getBody( ).add( tdh );
tdh.setDataSet( designHandle.findDataSet( "ds2" ) );
ParamBinding textBinding = StructureFactory.createParamBinding( );
textBinding.setParamName( "param1" ); //$NON-NLS-1$
textBinding.setExpression("10101");
PropertyHandle tableBindingHandle = tdh.getPropertyHandle(
TableHandle.PARAM_BINDINGS_PROP );
tableBindingHandle.addItem( textBinding );
PropertyHandle computedSet = tdh.getColumnBindings( );
ComputedColumn cs1, cs2;
cs1 = StructureFactory.createComputedColumn();
cs1.setName("ordernum");
cs1.setExpression("dataSetRow[\"ORDERNUMBER\"]");
computedSet.addItem(cs1);
cs2 = StructureFactory.createComputedColumn();
cs2.setName("productcode");
cs2.setExpression("dataSetRow[\"PRODUCTCODE\"]");
//cs2.setDataType(dataType)
computedSet.addItem(cs2);
designHandle.saveAs("output/desample/structfactorytestParm.rptdesign " );
designHandle.close( );
Platform.shutdown();
System.out.println("Finished");
}catch (Exception e){
e.printStackTrace();
}
}
}
Jason
Malte Wiskott wrote:
> Hi all,
>
> I'm generating a birt report with the birt api.
> I'm trying to bind a dataset to a TextDataHandle
> and by passing a parameter to the dataset.
> When I make this with the designer it works.
>
> In the same project, I made this for a table and it works perfectly,
> but with the TextDataHandle I have troubles.
>
> When I replace the ValueExpr with a static text it works...
> (but not the way I want :-)
>
> <code>
>
> // Creating the dynamic text handle
> TextDataHandle textDataPeriod = rpt.getElementFactory().newTextData(null);
>
> // Adding the data set
> textDataPeriod.setProperty(IReportItemModel.DATA_SET_PROP,Co nstants.PUB_PERIOD_SET_NAME);
>
>
> // set the value of a col of the dataset
> textDataPeriod.setValueExpr("row[\"periodName\"]");
>
> PropertyHandle dataItemParamBindingHandle =
> textDataPeriod.getPropertyHandle(DataItemHandle.PARAM_BINDIN GS_PROP);
>
> // setting the parameter for the dataset
> ParamBinding paramCtry = StructureFactory.createParamBinding();
> paramCtry.setParamName("ctry");
> paramCtry.setExpression("row[\"CTRY\"]");
> dataItemParamBindingHandle.addItem(paramCtry);
>
> </code>
>
>
> I get this error when I try to save the file
>
>
> java.lang.NullPointerException
> at
> org.eclipse.birt.report.model.core.DesignElement.setProperty (DesignElement.java:1162)
>
> at
> org.eclipse.birt.report.model.core.DesignElement.setProperty (DesignElement.java:1139)
>
> at
> org.eclipse.birt.report.model.util.BoundDataColumnUtil.creat eBoundDataColumn(BoundDataColumnUtil.java:321)
>
> at
> org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.h andleBoundsForParamBinding(BoundColumnsWriterMgr.java:281)
>
> at
> org.eclipse.birt.report.model.util.BoundColumnsMgr.dealRepor tItem(BoundColumnsMgr.java:108)
>
> at
> org.eclipse.birt.report.model.util.BoundColumnsMgr.dealTextD ata(BoundColumnsMgr.java:681)
>
> at
> org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.d ealTextData(BoundColumnsWriterMgr.java:592)
>
> at
> org.eclipse.birt.report.model.util.BoundColumnsMgr.dealNonDa taContainerReportItem(BoundColumnsMgr.java:159)
>
> at
> org.eclipse.birt.report.model.util.BoundColumnsMgr.dealTable (BoundColumnsMgr.java:440)
>
> at
> org.eclipse.birt.report.model.writer.BoundColumnsWriterMgr.d ealTable(BoundColumnsWriterMgr.java:535)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriter.visitTable (ModuleWriter.java:1911)
>
> at
> org.eclipse.birt.report.model.elements.TableItem.apply(Table Item.java:89)
> at
> org.eclipse.birt.report.model.writer.ModuleWriter.writeConte nts(ModuleWriter.java:2622)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriter.writeConte nts(ModuleWriter.java:2643)
>
> at
> org.eclipse.birt.report.model.writer.DesignWriter.visitRepor tDesign(DesignWriter.java:140)
>
> at
> org.eclipse.birt.report.model.elements.ReportDesign.apply(Re portDesign.java:89)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriter.writeFile( ModuleWriter.java:306)
>
> at
> org.eclipse.birt.report.model.writer.ModuleWriter.write(Modu leWriter.java:272)
>
> at
> org.eclipse.birt.report.model.api.ModuleHandle.save(ModuleHa ndle.java:1561)
> at
> org.eclipse.birt.report.model.api.ModuleHandle.saveAs(Module Handle.java:1581)
>
> at
> ch.is.isis4.reports.birt.SalesReport.buildReport(SalesReport .java:207)
>
>
> Can please someone help me here.
>
> Sincerely
>
> Malte Wiskott
|
|
|
Powered by
FUDForum. Page generated in 0.02904 seconds