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)
public class TestScriptlet implements IReportScriptlet
{
    private boolean m_firstTime= true ;
    public TestScriptlet()
    {
 
    }
    /*
    * @see com.bas.basserver.documents.IReportScriptlet#beforeReportInit(com.bas.basserver.documents.IReportEnvironment)
    */
    public void beforeReportInit(IReportEnvironmentenvironment)
    throws Exception
    {
 
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#afterReportInit(com.bas.basserver.documents.IReportEnvironment)
     */
    public void afterReportInit(IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /*
    * @see com.bas.basserver.documents.IReportScriptlet#beforePageInit(com.bas.basserver.documents.IReportEnvironment)
    */
    public void beforePageInit(IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /* (non-Javadoc)
     * @see com.bas.basserver.documents.IReportScriptlet#afterPageInit(com.bas.basserver.documents.IReportEnvironment)
     */
    public void afterPageInit(IReportEnvironmentenvironment)
    throws Exception
    {
 
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#beforeColumnInit(com.bas.basserver.documents.IReportEnvironment)
     */ 
    public void beforeColumnInit(IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#afterColumnInit(com.bas.basserver.documents.IReportEnvironment)
     */
    public void afterColumnInit(IReportEnvironmentenvironment)
    throws Exception
    {
 
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#beforeGroupInit(java.lang.String, com.bas.basserver.documents.IReportEnvironment)
     */
    public void beforeGroupInit(
        StringgroupName,
        IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#afterGroupInit(java.lang.String, com.bas.basserver.documents.IReportEnvironment)
     */
    public void afterGroupInit(
        StringgroupName,
        IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#beforeDetailEval(com.bas.basserver.documents.IReportEnvironment)
     */
    public void beforeDetailEval(IReportEnvironmentenvironment)
    throws Exception
    {
    }
    /*
     * @see com.bas.basserver.documents.IReportScriptlet#afterDetailEval(com.bas.basserver.documents.IReportEnvironment)
      */
       public void afterDetailEval(IReportEnvironmentenvironment)
       throws Exception
       {
        // here all report elements have been calculated already
        StringfirstName=(String)environment.getElementValue ("FirstName");
        StringlastName =(String)environment.getElementValue ("LastName");
        StringcurList =(String)environment.getElementValue ("NamesList");
        if (curList== null )
            curList="";
            // create the string with names
        if (m_firstTime)
            m_firstTime= false ;
        else
            curList=curList+",";
            // set the value for our element
        environment.setElementValue("NamesList",curList+firstName+" "+lastName);
        // set the value for another element
        ImageIconimage= new ImageIcon(getClass().getResource("/com/bas/uiconfiguration/images/arrowLeft.gif"));
        environment.setElementValue("Image",image.getImage());
    }
}
  • Last modified: 2023/04/06 04:47