Index

JReport DHTML API

The DHTML API is a set of java programming interfaces, which allow you customize the DHTML feature of JReport Enterprise Server; so that you can conveniently use the JReport DHTML feature (completely or partially) in your product.

Installation

DHTML API is a part of server API.

When you install JReport Enterprise Server, JReport Server API (including DHTML API) will be installed as well. After installation, you should have the following components under %JREntServerHome%:

lib\JRESServlets.jar
lib\JREngine.jar
lib\servlet.jar
lib\hsqldb.jar
(since v5.2, this file must be included)

Server API classes are stored in the archive files - JRESServlets.jar.

You need to set the CLASSPATH environment variable before you compile and run the program. Append the following string to your CLASSPATH starting the Server API:

For server:
%JREntServerHome%\lib\JRESServlets.jar;
%JREntServerHome%\lib\JREngine.jar;
%JREntServerHome%\lib\servlet.jar;

For DHTML, please also include:
%JREntServerHome%\lib\JRWebDesign.jar;

Packages

The DHTML API consists of the following packages:

jet.web.dhtml .......... Contains some interfaces of JReport DHTML, with which you can conveniently use JReport DHTML feature in your product, completely or partially.

Main Interfaces and Classes

Getting Started With JReport DHTML API

How to get an instance of DHTML API

Please note that before you can use the following methods to get a DHTML API instance, you need to import some relevant packages; for instance, jet.web.dhtml.* must be included here.

  1. For local use

    Both of the following methods can be used to get the instance of DHTML API locally. The results of these two methods are exactly the same.

    Method 1:

    DHtmlAPI service = DHTMLService.getDHtmlAPI();

    Method 2:

    HttpRptServer server;
    if (System.getProperty(APIConst.REMOTE_DISPATCHER) == null) {
        server = HttpUtil.getHttpRptServer();
    } else {
        server = RemoteDispatcherFactory.getInstance().getDispatchedServer(request);
    }
    DHtmlAPI service = (DHtmlAPI)server.getSimpleDHtmlService();
  2. For RMI use

    This method can be used to get the instance of DHTML API from a remote server (RMI).

    HttpRptServer server;
    if (System.getProperty(APIConst.REMOTE_DISPATCHER) == null) {
        server = HttpUtil.getHttpRptServer();
    } else {
        server = RemoteDispatcherFactory.getInstance().getDispatchedServer(request);
    }
    SimpleDHtmlAPI service = server.getSimpleDHtmlService();

Advanced DHTML API application

Besides the fundamental functions that DHTML API provides, you can also customize your DHTML at the component level (or lower level), using jet.web.dhtml.DHTMLTookit. Please note that this interface doesn't support RMI and can only be used locally.

How to get an instance of DHTML Toolkit

//Get a DHTML API instance using the method 1 or     
//2 provided in the preceding section,  and then     
//use the following method to get an instance of     
//DHTML Tookit.                                      

//The instance "service" is supposed to be derived   
//from the above method 1 or 2.                      

DHTMLToolkit toolkit = service.getDHTMLToolkit();

Use DHTML Toolkit to customize your DHTML

  1. Component Customization

    <%
        try
        {
            //Gets DHTML API instance and DHTMLToolkit instance. 
            DHtmlAPI service = DHTMLService.getDHtmlAPI();
            DHTMLToolkit toolkit=service.getDHTMLToolkit();
            String id=service.getUserID(request);

            String[][] js={{"dialog.js", "skinjs"},{"DHTML.js", null},{"dmpage.js", null},{"connect.js", null},{"DHTMLapi.js", null},{"dragOverlayer.js",null},{"tree.js", null},{"util.js",null},{"layout.js",null}};
            String[][] css={{"dialog.css","skincss"},{"classic.css", null},{"ie.css",null}};

            //The two parameters "null" must be set, otherwise   
            //the customization will not take effect.            

            toolkit.setLayoutFunction(null,null);

            //You can also use getMainPage() as a substitute     
            //of the following two lines of code.                
            //Gets the content of DHTML header.                  
            response.getWriter().write(toolkit.getHeader("Header","GBK",null,js,css).toString());

            //For print, this method must be called.      
            response.getWriter().write(toolkit.getPrintObject("",0).toString());

            //Gets the content of DHTML mainpage body.           
            response.getWriter().write(toolkit.getBody("",0,0,"#FF0000",0,"initOPCount(6)","","",id).toString());
            //Gets the content of DHTML connect frame.           
            response.getWriter().write(toolkit.getConnectFrame(id,"",0,0,0,720,1).toString());

           
            //Gets the content of DHTML menu.                    
            response.getWriter().write(toolkit.getMenu(id, "", 0, 60).toString());
            //Gets the content of DHTML navigation bar.                 
            response.getWriter().write(toolkit.getNavibar(id, "", 0, 20).toString());
            //Gets the content of DHTML Toolbar.                 
            response.getWriter().write(toolkit.getToolbar(id, "", 0, 40) .toString());
            //Gets the content of DHTML user information panel.  
            service.setUserbarVisible(id, true);
    response.getWriter().write(toolkit.getUserbar(id, "", 0, 90).toString());
            //Gets the content of DHTML Sort Panel.              
            response.getWriter().write(toolkit.getSortPanel(id, "", 0, 0, 160, 900, 20).toString());
            //Gets the content of DHTML Filter Panel.            
            response.getWriter().write(toolkit.getFilterPanel(id, "", 0, 0, 200, 900, 20).toString());
            //Gets the content of DHTML Table Of Content.        
            service.setTocVisible(id, true);
    response.getWriter().write(toolkit.getTOCBrowser(id, "", 0, 10, 110, 150, 300).toString());
            //Gets the content of DHTML Report Browser.          
            response.getWriter().write(toolkit.getReportBrowser(id, "",0,150, 110, 720, 500).toString());
            //Gets the content of DHTML footer.                  
            response.getWriter().write(toolkit.getFooter(true).toString());


        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }

    %>
  2. Action Customization

    <%
        try
        {
            DHtmlAPI service = DHTMLService.getDHtmlAPI();
            String id=service.getUserID(request);
            DHTMLToolkit toolkit=service.getDHTMLToolkit();
            response.getWriter().write(toolkit.getMainPageHeader(id,"",1,0).toString());

    %>
    <p><input type="button" value="getExceDialogAct" name="ExceDialog" onClick="<%=toolkit.getExcelDialogAct(id,true,"Excel Dialog Title",500,200)%>"></p>
    <p><input type="button" value="getExitAct" name="Exit" onClick="<%=toolkit.getExitAct(id)%>"</p>
    <p><input type="button" value="getPrintDialogAct" name="PrintDialog" onClick="<%=toolkit.getPrintDialogAct()%>"></p>
    <p><input type="button" value="getSaveRstDialogAct" name="SaveRstDialog" onClick="<%=toolkit.getSaveRstDialogAct(id)%>"></p>
    <p><input type="button" value="getSearchDialogAct " name="SearchDialog" onClick="<%=toolkit.getSearchDialogAct(id)%>"></p>
    <%
    }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
    %>
    </body>
    </html>

API Demos

You can refer to the two built-in JSPs (dhtml.jsp and mainpage.jsp) that come with the JReport Enterprise Server product as a demo, located under %JREntServer%\public_html\jinfonet\dhtmljsp.

Additional References

Index