Report Scriptlet Example

The following example shows the code for a simple scriptlet that accumulates names encountered in the report and provides them in a single comma separated string. It also displays a static image. It is assumed that the report in which the scriptlet executes has the following elements:

  1. Tag element with the name “FirstName”
  2. Tag element with the name “Last Name”
  3. Text element with the name “NamesList” (the scriptlet is attached to this element)
  4. Image element with the name “Image” (the scriptlet is also attached to this element)
  1. public class TestScriptlet implements IReportScriptlet
  2. {
  3. private boolean m_firstTime= true ;
  4. public TestScriptlet()
  5. {
  6.  
  7. }
  8. /*
  9.   * @see com.bas.basserver.documents.IReportScriptlet#beforeReportInit(com.bas.basserver.documents.IReportEnvironment)
  10.   */
  11. public void beforeReportInit(IReportEnvironmentenvironment)
  12. throws Exception
  13. {
  14.  
  15. }
  16. /*
  17.   * @see com.bas.basserver.documents.IReportScriptlet#afterReportInit(com.bas.basserver.documents.IReportEnvironment)
  18.   */
  19. public void afterReportInit(IReportEnvironmentenvironment)
  20. throws Exception
  21. {
  22. }
  23. /*
  24.   * @see com.bas.basserver.documents.IReportScriptlet#beforePageInit(com.bas.basserver.documents.IReportEnvironment)
  25.   */
  26. public void beforePageInit(IReportEnvironmentenvironment)
  27. throws Exception
  28. {
  29. }
  30. /* (non-Javadoc)
  31.   * @see com.bas.basserver.documents.IReportScriptlet#afterPageInit(com.bas.basserver.documents.IReportEnvironment)
  32.   */
  33. public void afterPageInit(IReportEnvironmentenvironment)
  34. throws Exception
  35. {
  36.  
  37. }
  38. /*
  39.   * @see com.bas.basserver.documents.IReportScriptlet#beforeColumnInit(com.bas.basserver.documents.IReportEnvironment)
  40.   */
  41. public void beforeColumnInit(IReportEnvironmentenvironment)
  42. throws Exception
  43. {
  44. }
  45. /*
  46.   * @see com.bas.basserver.documents.IReportScriptlet#afterColumnInit(com.bas.basserver.documents.IReportEnvironment)
  47.   */
  48. public void afterColumnInit(IReportEnvironmentenvironment)
  49. throws Exception
  50. {
  51.  
  52. }
  53. /*
  54.   * @see com.bas.basserver.documents.IReportScriptlet#beforeGroupInit(java.lang.String, com.bas.basserver.documents.IReportEnvironment)
  55.   */
  56. public void beforeGroupInit(
  57. StringgroupName,
  58. IReportEnvironmentenvironment)
  59. throws Exception
  60. {
  61. }
  62. /*
  63.   * @see com.bas.basserver.documents.IReportScriptlet#afterGroupInit(java.lang.String, com.bas.basserver.documents.IReportEnvironment)
  64.   */
  65. public void afterGroupInit(
  66. StringgroupName,
  67. IReportEnvironmentenvironment)
  68. throws Exception
  69. {
  70. }
  71. /*
  72.   * @see com.bas.basserver.documents.IReportScriptlet#beforeDetailEval(com.bas.basserver.documents.IReportEnvironment)
  73.   */
  74. public void beforeDetailEval(IReportEnvironmentenvironment)
  75. throws Exception
  76. {
  77. }
  78. /*
  79.   * @see com.bas.basserver.documents.IReportScriptlet#afterDetailEval(com.bas.basserver.documents.IReportEnvironment)
  80.   */
  81. public void afterDetailEval(IReportEnvironmentenvironment)
  82. throws Exception
  83. {
  84. // here all report elements have been calculated already
  85. StringfirstName=(String)environment.getElementValue ("FirstName");
  86. StringlastName =(String)environment.getElementValue ("LastName");
  87. StringcurList =(String)environment.getElementValue ("NamesList");
  88. if (curList== null )
  89. curList="";
  90. // create the string with names
  91. if (m_firstTime)
  92. m_firstTime= false ;
  93. else
  94. curList=curList+",";
  95. // set the value for our element
  96. environment.setElementValue("NamesList",curList+firstName+" "+lastName);
  97. // set the value for another element
  98. ImageIconimage= new ImageIcon(getClass().getResource("/com/bas/uiconfiguration/images/arrowLeft.gif"));
  99. environment.setElementValue("Image",image.getImage());
  100. }
  101. }