Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BIRT » Set default value of a dynamic listbox parameter (Set default value with value retrieved from another query)
icon5.gif  Set default value of a dynamic listbox parameter [message #779920] Mon, 16 January 2012 20:25 Go to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 66
Registered: August 2011
Member
I have a parameter that is a listbox (allow multiple values) that is filled by items retrieved from a dataset, i want to set the default selected value with the result of another query(dataset), is it possible ? How ?

In some other situation i want to set the first item as default value, is it possible either ?


Thanks.
Re: Set default value of a dynamic listbox parameter [message #780419 is a reply to message #779920] Tue, 17 January 2012 18:57 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

You may want to look over these two examples:
http://www.birt-exchange.org/org/devshare/designing-birt-reports/1198-default-value-all-with-multiselect-parsmeter/

http://www.birt-exchange.org/org/devshare/designing-birt-reports/356-all-parameter-values/

You could also call the data engine api from script. See attached example.

Jason
On 1/16/2012 3:25 PM, Alessio Pollero wrote:
> I have a parameter that is a listbox (allow multiple values) that is
> filled by items retrieved from a dataset, i want to set the default
> selected value with the result of another query(dataset), is it possible
> ? How ?
> In some other situation i want to set the first item as default value,
> is it possible either ?
>
> Thanks.
Re: Set default value of a dynamic listbox parameter [message #783228 is a reply to message #780419] Wed, 25 January 2012 10:19 Go to previous messageGo to next message
Alessio Pollero is currently offline Alessio PolleroFriend
Messages: 66
Registered: August 2011
Member
Yes the solution in dataenginealldefaultparmval.zip could fit my situation, the problem however is that if i run the report from the designer it works without any problem, but how can i get the default selected value from the API ?

I have tried with :

IScalarParameterDefn p = ...
p.getDefaultValue()

but it returns null ... How can i get the selection list from the API ?

I can't find where this default value can be retrieved from the API.

Thanks for your help.
Re: Set default value of a dynamic listbox parameter [message #783364 is a reply to message #783228] Wed, 25 January 2012 15:32 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Take a look at this api sample. If you are using 3.7 remove the
setBIRTHome call.

Jason



import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.logging.Level;

import org.eclipse.birt.core.framework.Platform;
import org.eclipse.birt.report.engine.api.EngineConfig;
import org.eclipse.birt.report.engine.api.EngineException;
import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;
import org.eclipse.birt.report.engine.api.IParameterDefnBase;
import org.eclipse.birt.report.engine.api.IParameterGroupDefn;
import org.eclipse.birt.report.engine.api.IParameterSelectionChoice;
import org.eclipse.birt.report.engine.api.IReportEngine;
import org.eclipse.birt.report.engine.api.IReportEngineFactory;
import org.eclipse.birt.report.engine.api.IReportRunnable;
import org.eclipse.birt.report.engine.api.IScalarParameterDefn;
import org.eclipse.birt.report.engine.api.ReportEngine;
import org.eclipse.birt.report.model.api.CascadingParameterGroupHandle;
import org.eclipse.birt.report.model.api.ReportDesignHandle;
import org.eclipse.birt.report.model.api.ScalarParameterHandle;

public class ReportParameterList {

static void executeReport() throws EngineException
{
HashMap parmDetails = new HashMap();
IReportEngine engine=null;
EngineConfig config = null;
try{

config = new EngineConfig( );

config.setBIRTHome("C:\\birt\\birt-runtime-2_6_1\\birt-runtime-2_6_1\\ReportEngine");
config.setLogConfig(null, Level.OFF);
Platform.startup( config );
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(
IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );
engine = factory.createReportEngine( config );
}catch( Exception ex){
ex.printStackTrace();
}


//Open a report design
IReportRunnable design =
engine.openReportDesign("reports/parmlist.rptdesign");

IGetParameterDefinitionTask task =
engine.createGetParameterDefinitionTask( design );

Collection params = task.getParameterDefns( true );

//task.getDefaultValue(arg0);


//task.getSelectionListForCascadingGroup();
Iterator iter = params.iterator( );
while ( iter.hasNext( ) )
{
IParameterDefnBase param = (IParameterDefnBase) iter.next( );

if ( param instanceof IParameterGroupDefn )
{
IParameterGroupDefn group = (IParameterGroupDefn) param;
System.out.println( "Parameter Group: " + group.getName( ) );
System.out.println(group.getPromptText());


// Do something with the parameter group.
// Iterate over group contents.

Iterator i2 = group.getContents( ).iterator( );
while ( i2.hasNext( ) )
{
IScalarParameterDefn scalar = (IScalarParameterDefn)
i2.next( );

//System.out.println("\t" + scalar.getName());
parmDetails.put( scalar.getName(), loadParameterDetails(
task, scalar, design, group));
}

}
else
{

IScalarParameterDefn scalar = (IScalarParameterDefn) param;
//System.out.println(param.getName());
parmDetails.put( scalar.getName(),loadParameterDetails( task,
scalar, design, null));


}
}

task.close();
engine.destroy();
}

private static HashMap loadParameterDetails(IGetParameterDefinitionTask
task, IScalarParameterDefn scalar, IReportRunnable report,
IParameterGroupDefn group){



HashMap parameter = new HashMap();

if( group == null){
parameter.put("Parameter Group", "Default");
}else{
parameter.put("Parameter Group", group.getName());
}
parameter.put("Name", scalar.getName());
parameter.put("Help Text", scalar.getHelpText());
parameter.put("Display Name", scalar.getDisplayName());
//this is a format code such as > for UPPERCASE
parameter.put("Display Format", scalar.getDisplayFormat());

if( scalar.isHidden() ){
parameter.put("Hidden", "Yes");
}else{
parameter.put("Hidden", "No");
}
if( scalar.isValueConcealed() ){
parameter.put("Conceal Entry", "Yes"); //ie passwords etc
}else{
parameter.put("Conceal Entry", "No");
}


switch (scalar.getControlType()) {
case IScalarParameterDefn.TEXT_BOX: parameter.put("Type", "Text
Box"); break;
case IScalarParameterDefn.LIST_BOX: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.RADIO_BUTTON: parameter.put("Type", "List
Box"); break;
case IScalarParameterDefn.CHECK_BOX: parameter.put("Type", "List
Box"); break;
default: parameter.put("Type", "Text Box");break;
}


switch (scalar.getDataType()) {
case IScalarParameterDefn.TYPE_STRING: parameter.put("Data Type",
"String"); break;
case IScalarParameterDefn.TYPE_FLOAT: parameter.put("Data Type",
"Float"); break;
case IScalarParameterDefn.TYPE_DECIMAL: parameter.put("Data Type",
"Decimal"); break;
case IScalarParameterDefn.TYPE_DATE_TIME: parameter.put("Data Type",
"Date Time"); break;
case IScalarParameterDefn.TYPE_BOOLEAN: parameter.put("Data Type",
"Boolean"); break;
case IScalarParameterDefn.TYPE_INTEGER: parameter.put("Data Type",
"Integer"); break;
default: parameter.put("Data Type", "Any"); break;
}


ScalarParameterHandle parameterHandle = ( ScalarParameterHandle )
scalar.getHandle();

parameter.put("Default Value", scalar.getDefaultValue());
parameter.put("Prompt Text", scalar.getPromptText());
parameter.put("Data Set Expression",
parameterHandle.getValueExpr());

if(scalar.getControlType() != IScalarParameterDefn.TEXT_BOX)
{
//System.out.println("dynamic parameter");

if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle ){
Collection sList = Collections.EMPTY_LIST;
if ( parameterHandle.getContainer( ) instanceof
CascadingParameterGroupHandle )
{

String groupName = parameterHandle.getContainer( ).getName( );
//used for Cascading parms see IGetParameterDefinitionTask.java
code for comments

//Need to load this for calls to get next level.
//This just gets the first level
Object [] keyValueTmp = new Object[1];
sList = task.getSelectionListForCascadingGroup( groupName,
keyValueTmp );


for ( Iterator sl = sList.iterator( ); sl.hasNext( ); )
{
IParameterSelectionChoice sI = (IParameterSelectionChoice) sl.next( );


Object value = sI.getValue( );
Object label = sI.getLabel( );
System.out.println( label + "--" + value);

}

}
}else{
//Normal Dynamic List
Collection selectionList = task.getSelectionList(
scalar.getName() );

if ( selectionList != null )
{
HashMap dynamicList = new HashMap();

for ( Iterator sliter = selectionList.iterator( );
sliter.hasNext( ); )
{
IParameterSelectionChoice selectionItem =
(IParameterSelectionChoice) sliter.next( );

Object value = selectionItem.getValue( );
String label = selectionItem.getLabel( );

//System.out.println( label + "--" + value);
//Display label unless null then display value. Value is
the what should get passed to the report.
dynamicList.put(value,label);

}
parameter.put("Selection List", dynamicList);
}
}

}



Iterator iter = parameter.keySet().iterator();
System.out.println("======================Parameter =" +
scalar.getName());
while (iter.hasNext()) {
String name = (String) iter.next();
if( name.equals("Selection List")){
HashMap selList = (HashMap)parameter.get(name);
Iterator selIter = selList.keySet().iterator();
while (selIter.hasNext()) {
Object lbl = selIter.next();
System.out.println( "Selection List Entry ===== Key = " + lbl + "
Value = " + selList.get(lbl));
}

}else{
System.out.println( name + " = " + parameter.get(name));
}
}
return parameter;

}

/**
* @param args
*/
public static void main(String[] args) {
try
{
executeReport( );
}
catch ( Exception e )
{
e.printStackTrace();
}
}

}


On 1/25/2012 5:19 AM, Alessio Pollero wrote:
> Yes the solution in dataenginealldefaultparmval.zip could fit my
> situation, the problem however is that if i run the report from the
> designer it works without any problem, but how can i get the default
> selected value from the API ?
> I have tried with :
> IScalarParameterDefn p = ...
> p.getDefaultValue()
>
> but it returns null ... How can i get the selection list from the API ?
> I can't find where this default value can be retrieved from the API.
>
> Thanks for your help.
Previous Topic:creating javascript vector from dataSetRow
Next Topic:Turn off bookmarks in PDF
Goto Forum:
  


Current Time: Fri Nov 28 17:30:19 GMT 2014

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

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