Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
how to add components in table
rang3r
Hi All,<br />
I was start learning BIRT. And i have a problem. I create a table (this OK, in Eclipse IDE i may see my table).<br />
But i cant add simple label in cell on my table.<br />
this is stackTrace:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
org.eclipse.birt.report.model.api.command.ContentException: Element "Label("MyLAbel")" is not allowed to be added into the (content) of "Table("myTable").Footer[0].Cells[0]", for it is already in the design tree.
at org.eclipse.birt.report.model.util.ContentExceptionFactory.createContentException(ContentExceptionFactory.java:43)
at org.eclipse.birt.report.model.command.AbstractContentCommand.add(AbstractContentCommand.java:120)
at org.eclipse.birt.report.model.command.AbstractContentCommand.add(AbstractContentCommand.java:255)
at org.eclipse.birt.report.model.api.SlotHandle.add(SlotHandle.java:126)
at org.eclipse.birt.report.model.api.SlotHandle.add(SlotHandle.java:80)
at CreateReport.buildReport(CreateReport.java:90)
at CreateReport.main(CreateReport.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
</pre>
and code of my class<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
import org.eclipse.birt.report.model.api.*;
import org.eclipse.birt.report.model.api.elements.table.LayoutTableModel;
import org.eclipse.birt.report.model.api.activity.SemanticException;
import org.eclipse.birt.report.model.api.command.ContentException;
import org.eclipse.birt.report.model.api.command.NameException;
import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.core.exception.BirtException;
import com.ibm.icu.util.ULocale;
import java.io.IOException;
public class CreateReport
{
public static void main( String[] args )
{
try
{
buildReport( );
}
catch ( IOException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch ( SemanticException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// This function shows how to build a very simple BIRT report with a
// minimal set of content: a simple grid with an image and a label.
static void buildReport( ) throws IOException, SemanticException
{
// Create a session handle. This is used to manage all open designs.
// Your app need create the session only once.
//Configure the Engine and start the Platform
DesignConfig config = new DesignConfig( );
config.setProperty("BIRT_HOME", "D:\\dowloads\\birt-runtime-2_6_0\\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 ) ;
// Create a new report design.
ReportDesignHandle design = session.createDesign( );
// The element factory creates instances of the various BIRT elements.
ElementFactory efactory = design.getElementFactory( );
// Create a simple master page that describes how the report will
// appear when printed.
//
// Note: The report will fail to load in the BIRT designer
// unless you create a master page.
DesignElementHandle element = efactory.newSimpleMasterPage( "Page Master" );
design.getMasterPages( ).add( element );
// Create a grid and add it to the "body" slot of the report
// design.
LabelHandle label=efactory.newLabel("MyLAbel");
label.setText(label.getText()+" + ljsgh;aljnlablsjkdg");
design.getBody().add(label);
TableHandle table=efactory.newTableItem("myTable",4,1,1,1);
design.getBody().add(table);
RowHandle tableheader = (RowHandle) table.getFooter().get( 0 );
CellHandle cell = (CellHandle) tableheader.getCells( ).get( 0 );
SlotHandle slot=cell.getSlot(0);
// model.getCell(model.getRowCount()-1,model.getColumnCount()-1).add("elem",label);
design.saveAs( "sample1.rptdesign" );
design.close( );
Platform.shutdown();
System.out.println("Finished");
}
}
</pre>
Please help me!<br />
THank you!
Find more posts tagged with
Comments
mwilliams
Hi rang3r,
You get this error with the line:
model.getCell(model.getRowCount()-1,model.getColumnCount()-1).add("elem",label);
commented out like in the code above? Or when you try to use that line? If it's when you try to use that line, try commenting out the line:
design.getBody().add(label);
Then you won't be attempting to have the same label with the same name in the design twice. That's just my first guess.
rang3r
Yes, my error in adding once label twice in report. When i created different labal, that curently work/ Thank you.
mwilliams
rang3r,
Not a problem. Glad to help. Let us know whenever you have questions!