Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:3500:0700:0730 [2023/04/05 07:50] – removed - external edit (Unknown date) 127.0.0.1docs:3500:0700:0730 [2023/04/06 04:47] (current) sean
Line 1: Line 1:
 +{{tag>Programmers_Reference Report_Scriptlets Example}}
 +[<10>]
 +===== 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:
 +
 +  - Tag element with the name "FirstName"
 +  - Tag element with the name "Last Name"
 +  - Text element with the name "NamesList" (the scriptlet is attached to this element)
 +  - Image element with the name "Image" (the scriptlet is also attached to this element)
 +
 +<code java>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());
 +    }
 +}</code>
 +