Overview
Description
This document introduces how to obtain and process the data submitted on the Data Entry Preview page as needed.
Implementation Method
You can set the data entry attribute by Built-in SQL and Custom Submission. The former is to bind fields on the data entry preview page with fields in the database table using the built-in SQL statements to achieve data entry, and the latter is to add custom events. If you need to obtain and process the submitted data, you can use the Custom Submission function.
Function Description
1. The function enables you to conduct personalized processing on the data submitted on the data entry preview page. Therefore, you need to write and maintain the codes used for data processing according to business requirements.
2. Callback is not supported at the moment, which means the data processing result will not be returned to the page for display.
3. The function is available on mobile terminals.
Example
Data Preparation
Create a dataset ds1, and extract data from FRDemo using the following SQL statement. SELECT * FROM SProduct limit 3.
Data Entry Table Designing
Drag the ProductID field into Cell A2 and Product_name into Cell B2, and add a Number Widget to Cell A2 and a Text Widget to Cell B2, as shown in the following figure.
Custom Submission Setting
Obtaining Template Data
Refer to the following code to obtain the corresponding template data, and then you can process the data as needed.
package com.fr.data;
import com.fr.log.FineLoggerFactory;
import com.fr.script.Calculator;
public class SubmitDemo extends DefinedSubmitJob {
public String getJobType() {
return " ";
}
/**
* If the parameter name added in the Data Entry Attribute page matches the following variable name, values will be automatically assigned to corresponding variables.
* The JobValue interface is to bind cell values. You can define the class for other types of data. For example, use String to bind string values.
* 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 parameter values as errors in fanruan.log.
if (ID.getState().checkChanged()) {
//FineLoggerFactory.getLogger().error("---------Modify:"+ID.getValue()+"------------");
//Output the data marked as Modify as errors in fanruan.log.
//FineLoggerFactory.getLogger().error("---------Add: "+ID.getValue()+"------------");
// Output the data marked as Add as errors in fanruan.log.
//FineLoggerFactory.getLogger().error("---------Delete:"+ID.getValue()+"------------");
// Output data marked as Delete as errors in fanruan.log.
//FineLoggerFactory.getLogger().error("---------Default:"+ID.getValue()+"------------");
// Output data marked as Default as errors in fanruan.log.
}
}
}
Obtaining Files
1. You need to import the following packages based on the code in the above section.
import com.fr.general.FArray;
import com.fr.cache.Attachment;
import com.fr.stable.xml.FRFile;
2. To obtain the name and bytes of Files uploaded through the text widget, further processing is required after you use the code JobValue.getValue().
If the parameter corresponding to the file cell is named FName, you can refer to the following code for processing after defining the object using private JobValue FName.
if (FName.getValue() instanceof FArray) {
FArray farray = (FArray) (FName.getValue());
for (int i = 0; i < farray.length(); i++) {
Attachment cache = (Attachment) (farray.elementAt(i));
FineLoggerFactory.getLogger().error("------filename:" + cache.getFilename() + "--------");
//getFilename()get the file name
FineLoggerFactory.getLogger().error("------file:" + cache.getBytes() + "--------");
//getBytes()get the bytes
}
}
else if (FName.getValue() instanceof FRFile){
FRFile cache = (FRFile) FName.getValue();
FineLoggerFactory.getLogger().error("------filename:" + cache.getFileName() + "--------");
//getFilename()get the file name
FineLoggerFactory.getLogger().error("------file:" + cache.getBytes() + "--------");
//getBytes()get the bytes
}
Data Entry Attribute Setting
1. Click Template, select Data Entry Attribute from the drop-down list, add a custom submission, and click Edit, as shown in the following figure.
2. Copy the above Java code and paste it to the editing page, click Compile, and click Save after the message"Successfully Compiled!" pops up, as shown in the following figure.
You can download the class file. SubmitDemo.rar
3. Click Add Attribute to add four attributes to the submit event. Ensure the value types are consistent with the types defined in the code, as shown in the following figure.
Effect Display
Select Data Entry Preview and click Submit.