LiteFlow LiteFlow
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
💒Home
📚Documents
💖Donation
🚀Plugin
  • About LiteFlow
  • Update Record
Community
Users
Gitee (opens new window)
Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • 🍤Introduction
  • 🍓Features
  • 🍟Quick Start(Hello world)

    • 🍄Notice
    • 🌿Springboot environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌱Spring environment

      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
    • 🌵Other environment

      • 🍄Notice
      • 🧬Dependency
      • ⚙️Config
      • 🛫Execute
  • 🍢Configuration item

    • 🍄Notice
    • 🌿Springboot environment
    • 🌱Spring environment
    • 🌵Other environment
  • 🗂Rules file

    • 📔Rules file format
    • 📕Local rule file
    • 📗Zookeeper source
    • 📘SQL database source
    • 📋Nacos source
    • 🗄Etcd source
    • 📙Custom source
  • 🔗General components

    • 📎Common component
    • ✂️Switch component
    • 📌If component
    • 🧬For component
    • ⛓While component
    • 🧿Break component
  • 🧩How to write EL rules

    • 🍄Notice
    • 🌴Serial mode
    • 🎋Parallel mode
    • 🌾Switch mode
    • 🌵If mode
    • 🌳Loop mode
    • 🍁Use sub chain
    • 🍂Use sub variables
    • 💐Complex example
    • 🌻About semicolons
    • 🌰About comments
    • 🐚Component Name Package
  • 🌮Data context

    • 🍄Notice
    • 🌯Definition and use
    • 🪶Pass initialized context
  • 🛩Flow executor

    • 🍄Notice
    • 🎡Executor method
    • 🎢Chain input parameter
    • 🎈LiteflowResponse object
  • 🍋Script component

    • 🍫Choose a script language
    • 🍕Define script component
    • 🌯Define file script
    • 🍣Interact with java
      • Interact with data context
      • Meta data
      • Interact with custom JavaBeans
    • 🍘Dynamic refresh script
  • 🍇Declarative component

    • 🥭What is a declarative component
    • 🧅Class level declaration
    • 🥥Method level declaration
  • 🎲Dynamic rules

    • 🍄Notice
    • 🎯How to build
  • 🎨Advanced features

    • 🍒Pre & Finally components
    • 🥠Substitute component
    • 🍉Component Parameters
    • 🍑Component alias
    • 🍍Component tag
    • 🥝Component event
    • 🥑Implicit chain
    • 🍕Private delivery
    • 🍣Component retry
    • 🍖Smooth hot refresh
    • 🍪Component aspect
    • 🍡Step information
    • 🧊Exceptions
    • 🧇Printing details
    • 🧁Custom request id
    • 🌭Multiple type rules
    • 🥗Asynchronous thread pool
    • 🍿Custom component executor
    • 🍥Simple monitor
    • 🧉DTD in Xml
  • ⛱Test cases and demo

    • 🪁Test cases
    • 🪀Demo
  • 🪂Performance
  • v2.9.X文档
  • 🍋Script component
铂赛东
2022-10-12
Contents

🍣Interact with java

# Interact with data context

Because LiteFlow component data is in the context, in a scripting language you can get the data by the camelCase of the className where you define the data context.

For example, your context class is called OrderContext, then the keyword orderContext is used in the script to obtain data or call methods.

If you have multiple contexts, you can also use multiple contexts in your script to get data or call logic methods inside the context.

For example, you want to get the userName object in the UserContext. You can write (using groovy as an example):

<node id="s1" name="common script component" type="script">
    <![CDATA[
        //you can define it like this
        def name = userContext.userName;
        //It can also be defined like this, if you have a getter method for userName
        def name = userContext.getUserName();
        //You can call any method in the data context
        userContext.doYourMethod();
    ]]>
</node>

# Meta data

Metadata can be obtained through the _meta keyword in the script, and metadata can be obtained through _meta.xxx. The metadata includes:

  • slotIndex: slot subscript, you can get slot data through FlowBus.getSlot(slotIndex)
  • currChainId: The id of the currently executing chain
  • nodeId: The ID of the currently executing node
  • tag: tag value, please refer to Component tag for the description of tag
  • cmpData: Component rule parameters, please refer to Component parameters for the description of cmpData
  • requestData: Process initial parameters
  • subRequestData: The input parameters of the current implicit process, if this node is arranged in the implicit process, it can be obtained, otherwise it cannot

# Interact with custom JavaBeans

Since v2.9.0, LiteFlow supports injecting any java object you define yourself in the script.

In the spring system, you only need to use the @ScriptBean annotation on the java object.

@Component
@ScriptBean("demo")
public class DemoBean1 {

    @Resource
    private DemoBean2 demoBean2;

    public String getDemoStr1(){
        return "hello";
    }

    public String getDemoStr2(String name){
        return demoBean2.getDemoStr2(name);
    }
}

In the above example, the demo keyword can be used directly in the script to call the getDemoStr1() and getDemoStr2() methods.

notice

It should be noted that the java object must be registered in the context in the spring system. If it is not registered in the context, it is useless to add the @ScriptBean annotation.

Under the non-spring system, if you want to inject your own defined java object into the script, you need to write the code manually (preferably when starting the application):

ScriptBeanManager.addScriptBean("demo", new DemoBean());
Help us improve this document (opens new window)
last update: 2022/11/30, 22:42:09
🌯Define file script
🍘Dynamic refresh script

← 🌯Define file script 🍘Dynamic refresh script→

Theme by Vdoing | Copyright © 2020-2022 铂赛东 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式