自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

報(bào)表參數(shù)的獲取與配置詳解

開發(fā) 后端
本文介紹報(bào)表參數(shù)的獲取和配置方法,從而實(shí)現(xiàn)通過程序進(jìn)行設(shè)計(jì)。參數(shù)是報(bào)表生成之前想報(bào)表設(shè)計(jì)文件輸入的報(bào)表元素。報(bào)表的應(yīng)用程序可以訪問報(bào)表的參數(shù)的屬性,最常用的屬性是name和value。

報(bào)表是有參數(shù)的,通過報(bào)表參數(shù)可以使用程序進(jìn)行獲取和配置。參數(shù)是報(bào)表生成之前想報(bào)表設(shè)計(jì)文件輸入的報(bào)表元素。報(bào)表的應(yīng)用程序可以訪問報(bào)表的參數(shù)的屬性,最常用的屬性是name和value,你可以使用參數(shù)名或通用編碼來獲取參數(shù)。

為報(bào)表設(shè)計(jì)創(chuàng)建一個(gè)參數(shù)定義任務(wù)

一個(gè)IGetParameterDefinitionTask對(duì)象提供鏈接到報(bào)表設(shè)計(jì)所有參數(shù)的接口。通過調(diào)用 ReportEngine.createGetParameterDefinitionTask( )創(chuàng)建一個(gè)參數(shù)定義對(duì)象,使用結(jié)束后調(diào)用他的close方法關(guān)閉。

測試報(bào)表設(shè)計(jì)是否有參數(shù)

IGetParameterDefinitionTask.getParameterDefns( )可以測試報(bào)表設(shè)計(jì)是否有參數(shù),它返回一個(gè)參數(shù)集合,調(diào)用集合的isEmpty( )方法可以測試集合中是否有元素。

獲取報(bào)表設(shè)計(jì)的參數(shù)

通過IGetParameterDefinitionTask.getParameterDefn( )方法獲取一個(gè)已知名字的參數(shù),它返回一個(gè)IParameterDefnBase類型對(duì)象,也可以調(diào)用getParameterDefns( )方法返回一個(gè)參數(shù)集合。

getParameterDefns( )需要一個(gè)boolean參數(shù),如果為false返回一個(gè)未分組的參數(shù)集合,如果為true返回報(bào)表設(shè)計(jì)中定義的參數(shù)組。

調(diào)用IParameterDefnBase.getParameterType( )可以檢驗(yàn)參數(shù)是否是一個(gè)組。如果是一個(gè)組則返回IParameterDefnBase.PARAMETER_GROUP,如果是一個(gè)級(jí)聯(lián)參數(shù)組則返回 IParameterDefnBase.CASCADING_PARAMETER_GROUP。為獲取一組報(bào)表參數(shù),使用方法 IParameterGroupDefn.getContents( ),它返回一個(gè)數(shù)據(jù)類型是IScalarParameterDefn的ArrayList對(duì)象。

獲取報(bào)表參數(shù)的默認(rèn)值

這個(gè)任務(wù)是可選的。調(diào)用IGetParameterDefinitionTask.getDefaultValue( )獲取一個(gè)已知參數(shù)的默認(rèn)值,它返回的是一個(gè)Object??梢酝ㄟ^調(diào)用IScalarParameterDefn.getDataType( )來獲取Object的有效類型,它返回一個(gè)IScalarParameterDefn定義的int類型的靜態(tài)變量。調(diào)用 IGetParameterDefinitionTask.getDefaultValues( )來獲取報(bào)表設(shè)計(jì)的所有參數(shù)的默認(rèn)值,它返回一個(gè)HashMap對(duì)象存儲(chǔ)了從參數(shù)名到默認(rèn)值的映射。

使用常量列表提供的效值

許多報(bào)表參數(shù)只接受常量列表的值,這些值可能是靜態(tài)常量,也可能是數(shù)據(jù)庫里查出來的數(shù)據(jù)list。使用 IGetParameterDefinitionTask.getSelectionList( )可以返回參數(shù)所能接受的參數(shù)(IParameterSelectionChoice)的集合,如果集合為null,則可以接受任何值。 IParameterSelectionChoice的getLabel( )方法返回現(xiàn)實(shí)的文本,getValue( )返回值。

獲取每個(gè)報(bào)表參數(shù)的屬性

這個(gè)任務(wù)是可選的。使用IScalarParameterDefn的方法可以獲取表參數(shù)的屬性。應(yīng)用程序使用屬性生成用戶自定義接口。例如,獲取參數(shù)的數(shù)據(jù)類型使用getDataType( )方法。

為參數(shù)設(shè)置值

調(diào)用IGetParameterDefinitionTask.setParameterValue( )為參數(shù)設(shè)置值。如果你是通過應(yīng)用程為日期數(shù)值等參數(shù)返回一個(gè)字符串,要把他們轉(zhuǎn)化成和本地?zé)o關(guān)的格式。調(diào)用方法 ReportParameterConverter.parse( )方法可以完成這項(xiàng)工作。getParameterValues( )方法返回一個(gè)HashMap包含了已經(jīng)設(shè)置的所有參數(shù)。

報(bào)表參數(shù)設(shè)置實(shí)例

下面的代碼展示了如何設(shè)置一個(gè)已知參數(shù)名的參數(shù)值:

  1. // Create a parameter definition task.    
  2. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );    
  3. // Instantiate a scalar parameter.    
  4. IScalarParameterDefn param = (IScalarParameterDefn)     
  5. task.getParameterDefn( "customerID" );    
  6. // Get the default value of the parameter. In this case,     
  7. // the data type of the parameter, customerID, is Double.    
  8. int customerID = ((Double) task.getDefaultValue( param )).intValue( );    
  9. // Get a value for the parameter. This example assumes that     
  10. // this step creates a correctly typed object, inputValue.    
  11. // Set the value of the parameter.    
  12. task.setParameterValue( "customerID", inputValue );    
  13. // Get the values set by the application for all parameters.    
  14. HashMap parameterValues = task.getParameterValues( );    
  15. // Close the parameter definition task.    
  16. task.close( );    
  17. // Create a parameter definition task.  
  18. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );  
  19. // Instantiate a scalar parameter.  
  20. IScalarParameterDefn param = (IScalarParameterDefn)   
  21. task.getParameterDefn( "customerID" );  
  22. // Get the default value of the parameter. In this case,   
  23. // the data type of the parameter, customerID, is Double.  
  24. int customerID = ((Double) task.getDefaultValue( param )).intValue( );  
  25. // Get a value for the parameter. This example assumes that   
  26. // this step creates a correctly typed object, inputValue.  
  27. // Set the value of the parameter.  
  28. task.setParameterValue( "customerID", inputValue );  
  29. // Get the values set by the application for all parameters.  
  30. HashMap parameterValues = task.getParameterValues( );  
  31. // Close the parameter definition task.  
  32. task.close( );  

下面的代碼展示了如何使用報(bào)表參數(shù)集合,例子中使用ReportParameterConverter將字符串轉(zhuǎn)化成用戶接口接受的參數(shù)格式。

  1. // Create a parameter definition task.    
  2. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );    
  3. // Create a collection of the parameters in the report design.    
  4. Collection params = task.getParameterDefns( false );    
  5. // Get the default values of the parameters.    
  6. HashMap parameterValues = task.getDefaultValues( );    
  7. // Get values for the parameters. Later code in this example    
  8. // assumes that this step creates a HashMap object,    
  9. // inputValues. The keys in the HashMap are the parameter    
  10. // names and the values are those that the user provided.    
  11. // Iterate through the report parameters, setting the values     
  12. // in standard locale-independent format.    
  13. Iterator iterOuter = params.iterator( );    
  14. ReportParameterConverter cfgConverter =    
  15.         new ReportParameterConverter( "", Locale.getDefault() );    
  16. while ( iterOuter.hasNext( ) ) {    
  17. IParameterDefnBase param = (IParameterDefnBase) iterOuter.next( );    
  18. String value = (String) inputValues.get( param.getName( ));    
  19. if ( value != null ) {    
  20. parameterValues.put( param.getName( ),     
  21. cfgConverter.parse( value, param.getDataType( ) ) );    
  22. }    
  23. }    
  24. // Close the parameter definition task.    
  25. task.close( );    
  26. // Create a parameter definition task.  
  27. IGetParameterDefinitionTask task = engine.createGetParameterDefinitionTask( runnable );  
  28. // Create a collection of the parameters in the report design.  
  29. Collection params = task.getParameterDefns( false );  
  30. // Get the default values of the parameters.  
  31. HashMap parameterValues = task.getDefaultValues( );  
  32. // Get values for the parameters. Later code in this example  
  33. // assumes that this step creates a HashMap object,  
  34. // inputValues. The keys in the HashMap are the parameter  
  35. // names and the values are those that the user provided.  
  36. // Iterate through the report parameters, setting the values   
  37. // in standard locale-independent format.  
  38. Iterator iterOuter = params.iterator( );  
  39. ReportParameterConverter cfgConverter =  
  40.         new ReportParameterConverter( "", Locale.getDefault() );  
  41. while ( iterOuter.hasNext( ) ) {  
  42. IParameterDefnBase param = (IParameterDefnBase) iterOuter.next( );  
  43. String value = (String) inputValues.get( param.getName( ));  
  44. if ( value != null ) {  
  45. parameterValues.put( param.getName( ),   
  46. cfgConverter.parse( value, param.getDataType( ) ) );  
  47. }  
  48. }  
  49. // Close the parameter definition task.  
  50. task.close( );  

使用級(jí)聯(lián)參數(shù)

級(jí)聯(lián)參數(shù)參數(shù)是一組可供用戶選擇的參數(shù)值的集合。第一個(gè)參數(shù)的選擇會(huì)影響到第二個(gè)參數(shù)中的值。參數(shù)使用一個(gè)或多個(gè)查詢來從數(shù)據(jù)集把數(shù)據(jù)展示給用戶。參數(shù)定義任務(wù)根據(jù)前面的選擇以行為單位過濾參數(shù)組中的數(shù)據(jù)。

使用報(bào)表引擎實(shí)現(xiàn)級(jí)聯(lián)參數(shù),要進(jìn)行如下工作:

■使用IGetParameterDefinitionTask.evaluateQuery( )方法為級(jí)聯(lián)參數(shù)準(zhǔn)備數(shù)據(jù),它需要參數(shù)group的名字作為參數(shù)。

■調(diào)用IGetParameterDefinitionTask.getSelectionListForCascadingGroup( )獲取參數(shù)組的第一個(gè)參數(shù)的值,它需要兩個(gè)參數(shù),參數(shù)名和對(duì)象數(shù)組,對(duì)第一個(gè)參數(shù)來說這個(gè)數(shù)組是空的。該方法返回一個(gè) IParameterSelectionChoice集合。

■ 再次調(diào)用getSelectionListForCascadingGroup( )方法獲取后面的參數(shù),這次Object[ ]中放的是前面獲取的參數(shù)值。

下面的代碼展示了如何通過查詢實(shí)現(xiàn)級(jí)聯(lián)參數(shù):

  1. // Create a grouped collection of the design’s parameters.    
  2. Collection params = task.getParameterDefns( true );    
  3. // Iterate through the parameters to find the cascading group.    
  4. Iterator iter = params.iterator( );    
  5. while ( iter.hasNext( ) ) {    
  6. IParameterDefnBase param = (IParameterDefnBase) iter.next();    
  7. if ( param.getParameterType() ==     
  8. IParameterDefnBase.CASCADING_PARAMETER_GROUP ) {    
  9. ICascadingParameterGroup group = (ICascadingParameterGroup) param;    
  10. Iterator i2 = group.getContents( ).iterator( );    
  11. // Run the query for the cascading parameters.    
  12. task.evaluateQuery( group.getName() );    
  13. Object[ ] userValues = new Object[group.getContents( ).size( )];    
  14. // Get the report parameters in the cascading group.    
  15. int i = 0;    
  16. while ( i2.hasNext( ) ) {    
  17. IScalarParameterDefn member = (IScalarParameterDefn) i2.next( );    
  18. // Get the values for the parameter.    
  19. Object[ ] setValues = new Object[i];    
  20. if ( i > 0 )  System.arraycopy( userValues, 0, setValues, 0, i );    
  21. Collection c = task.getSelectionListForCascadingGroup(    
  22.    group.getName(),setValues );    
  23. // Iterate through the values for the parameter.    
  24. Iterator i3 = c.iterator();    
  25. while ( i3.hasNext( ) ) {    
  26. IParameterSelectionChoice s =     
  27. ( IParameterSelectionChoice ) i3.next( );    
  28. String choiceValue = s.getValue( );    
  29. String choiceLabel = s.getLabel( );    
  30. }    
  31. // Get the value for the parameter from the list of    
  32. // choices. This example does not provide the code for    
  33. // this task.    
  34. userValues[i] = inputChoiceValue;    
  35. i++;    
  36. }    
  37. }    
  38. }    

以上就是用程序處理報(bào)表參數(shù)的配置方法。

【編輯推薦】

  1. Java報(bào)表工具FineRpeort特性概覽
  2. Java報(bào)表工具的簡約之美
  3. Java多線程編程實(shí)戰(zhàn)精要
  4. Java內(nèi)部類使用的四點(diǎn)建議
  5. 深入核心 Java終止函數(shù)詳解
責(zé)任編輯:yangsai 來源: JavaEye博客
相關(guān)推薦

2010-11-29 13:33:00

sybase配置參數(shù)

2010-09-26 11:00:48

JVM參數(shù)配置

2018-11-01 10:34:37

JVM內(nèi)存配置

2010-09-17 15:57:23

TomcatJVM

2023-09-01 08:18:53

Tomcat配置參數(shù)

2009-07-09 14:02:58

Tomcat JDK

2009-07-04 00:50:38

2024-01-15 16:46:35

Nginx服務(wù)器

2011-03-02 13:28:33

Vsftpd配置

2009-03-10 13:51:36

編譯器VS2010C#

2010-08-12 13:15:26

MySQL集群

2010-06-03 15:04:31

NAP IPSEC配置

2010-06-21 14:57:32

Linux apt

2010-07-19 11:35:05

2010-04-02 17:11:45

Oracle數(shù)據(jù)庫

2010-08-23 09:14:18

Visual Stud

2011-06-21 17:23:40

QT 編譯

2009-08-31 15:54:35

2010-08-09 10:25:20

DB2配置向?qū)渲脜?shù)

2010-07-02 14:52:21

SQL Server元
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)