Successfully!

Error!

You are viewing 10.0 help doc. More details are displayed in the latest help doc

Custom Submission

1 Overview

1.1 Problem Description

When designing a data entry report, users hope that after clicking the submit button, the data on the filling page can be obtained for some custom processing. How can this be achieved?

1.2 Implementation ideas

In the "Data Entry Attribute" chapter, that there are 2 ways to set the data entry attributes. One is to directly bind the fields with built-in SQL to fill in the data in the database, and the other is to add custom events. If you need to perform custom processing on the data after obtaining it, you can choose to use custom submission.

1.3 Function Description

1) The essence of custom submission is to do custom processing after obtaining page data, so the code part after obtaining the value needs to be written and maintained by the user according to business needs.

2) Callback is not supported right now, that is, the result of data processing is returned to the page for display.

3) Custom submission supports mobile use.

2. Examples

2.1 Prepare data

Create a new dataset ds1, fetch data from FRDemo, and the SQL statement is:SELECT * FROM S product limit 3


2.2 Design the report

Design the report, drag the corresponding field of the data set into the cell, add a "Number" widget to cell A2, and add a "Text Field" widget to cell B2. The table style is shown in the figure below:


2.3 Write a custom submission class

2.3.1 Get template data

Refer to the following code to obtain the corresponding template data, and then process the data according to custom requirements.

package com.fr.data;

import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;

public class SubmitDemo extends DefinedSubmitJob {

    public String getJobType() {
        return " ";
    }

     /**
      * When the attibute name added to the template filling attribute is consistent with the variable name below, it will be automatically assigned to the corresponding variable
      * JobValue represents the bound value of the cell, and other types of data need to define classes according to their respective types, for example, a string is String
      * Cell groups are not supported
      */
    private JobValue ID;
    private JobValue Name;
    private String Type;
    private Integer Count;


    /**
     * Execute this method once for each record
     */
    public void doJob(Calculator calculator) throws Exception {
        FineLoggerFactory.getLogger().error("---------ID:" + ID.getValue() + ",Name:" + Name.getValue() + ",Type:" + Type + ",Count:" + Count + "------------");
        //Output the obtained attribute values at the error level in fanruan.log
        if (ID.getState().checkChanged()) {
            //FineLoggerFactory.getLogger().error("---------modify:"+ID.getValue()+"------------");
            // Output data marked as "modified" at error level in fanruan.log
        } else if (ID.getState().checkInsert()) {
            //FineLoggerFactory.getLogger().error("---------add:"+ID.getValue()+"------------");
            // Output the data marked as "new" at the error level in fanruan.log
        } else if (ID.getState().checkDeleted()) {
            //FineLoggerFactory.getLogger().error("---------delete:"+ID.getValue()+"------------");
            // Output the data marked as "delete" at the error level in fanruan.log
        } else if (ID.getState().checkDefault()) {
            //FineLoggerFactory.getLogger().error("---------default:"+ID.getValue()+"------------");
            // Output data marked as "default" at error level in fanruan.log
        }
    }
}

2.3.2 Get files

1) The following packages need to be imported based on the code in section 2.3.1:

import com.fr.general.FArray;
import com.fr.cache.Attachment;
import com.fr.stable.xml.FRFile;

2) The file uploaded by the file control needs to be further processed after using JobValue.getValue() to obtain the file name and file stream.

Assuming that the attribute corresponding to the file cell is named FName, after using private JobValue FName to define the object, refer to the following code for processing:

2.4 Set the filling properties

1) Click "Template > Data Entry Attributes", add a Custom Submit, and click the Edit button:


2) Copy the above Java code to the custom function editing interface, click theCompile button, and after compiling successful, click the Save button, as shown in the following figure:

Note: In addition to the above compilation methods, you can also put the externally compiled class file in the %FR_HOME%\webapps\webroot\WEB-INF\classes folder in the same location as the package path defined in the code, and then click "Select Button" refers to the class file. If the modification replaces the class file, the designer or Fanruan service needs to be restarted for the modified code to take effect.

Click to download the class file:SubmitDemo.rar

3) Click the Add Attributes button to add 4 attributes to the submit event. Note that the type of the value must be consistent with the type defined in the code, as shown in the following figure:


2.5 Effect preview

Use the data entry preview, click the submit button, and then view the log.

Note: Mobile preview is supported.

3. Template download

Click to download the template: custom_submit.cpt



Attachment List


Theme: Data Entry
Already the First
Already the Last
  • Helpful
  • Not helpful
  • Only read

Doc Feedback