Assign Values To Session In The Report To Realize Parameter Sharing

  • Last update:  2021-02-18
  • I.Description

    If there are several different reports, each report has a common item to choose from, such as date and time. We hope that after selecting the time of the first report, the default time of other reports will become the time selected by the first report. How to achieve this?

    II.Ideas

    It can be achieved by assigning a value to the Session. Add a post-editing event that passes the value to the back-end servlet through the URL of AJAX to the parameter control of the first report. The servlet obtains the value passed by AJAX and saves it in the Session. The subsequent reports get the control value of the parameter. The Session value is sufficient.

    III.Operation steps

    1. AJAX pass value setting

    Just open a template with parameters, such as opening the template:%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\Primary\Parameter\Template_Parameter.cpt.

    Click on the parameter interface, set the control as a text control, and add post-editing events to the text control. The specific JavaScript code is as follows:

    var str=this.getValue();    //Get the value of the current control
    FR.ajax({  
       url: "/webroot/session/report?id="+encodeURIComponent(str)  //Pass the value to the Session Servlet
    });

    Note: If you want to preview the report and write the data to the Session without asynchronous loading, you can add async:false under AJAX.

    The detailed settings are shown in the figure below:

    1.png


    2. Get the value and save it to the Session

    Create a new class named Session, the specific code is detailed in:

    https://git.fanruan.com/demo/example/src/release/10.0/src/main/java/com/fr/data/session.java

    Compile the session.java class and place the compiled session.class in the%FR _HOME%\webapps\webroot\WEB-INF\classes\com\fr\datadirectory.


    3. Configure the servlet that accesses the session assignment

    In the newly created web.xml under%FR _HOME%\webroot\WEB-INF\, add the following code:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
       version="2.4">
      <display-name>Template WebApp</display-name>
        <mime-mapping>
      <extension>msi</extension>
      <mime-type>application/x-msi</mime-type>
      </mime-mapping>
      <servlet>
        <servlet-name>session</servlet-name>
        <servlet-class>com.fr.data.session</servlet-class>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>session</servlet-name>
        <url-pattern>/session/*</url-pattern>
      </servlet-mapping>
    </web-app>

    Note: When writing a Java class file, if it is saved under a specific package, for example, under com/fr/data, in addition to placing the class file under the corresponding location, the content in the web.xml file The servlet-class tag also needs to be modified, for example, to com.fr.data.session.


    4. Get Session value

    In another parameter template such as%FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\Primary\Parameter\Dataset_Parameter.cptDelete the default value of the regional parameter in the data set, and select the formula in the control value of the parameter control and enter$sessionname(The name of the Session in the Servlet).As shown below:

    2.png

    Note: sessionname refers to the sessionname in the Java class.


    5. Effect view

    Since the built-in designer Tomcat does not read web.xml now, the project needs to be deployed to the external Tomcat.

    Data Entry Preview Template_Parameter.cpt, enter China in the text box, and then preview Dataset_Parameter.cpt, you can see that China is displayed in the text box, as shown in the figure below:

    1.gif

    Attachment List


    Theme: Report Features
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy