Creating a dynamic drop-down list - Cloud - 8.0

Java custom code

Version
Cloud
8.0
Language
English
Product
Talend Big Data
Talend Big Data Platform
Talend Cloud
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Data Governance > Third-party systems > Custom code components (Integration) > Java custom code components
Data Quality and Preparation > Third-party systems > Custom code components (Integration) > Java custom code components
Design and Development > Third-party systems > Custom code components (Integration) > Java custom code components
In the first scenario, you have hard-coded the list in a tJava component. However, the items of the list might come from a data source. For example, the items can be stored in a database table and their number can be unknown.

This Job uses the following components:

  • a tMysqlInput component to query the people information from the employee table,
  • a tJavaFlex component to prepare the dynamic drop-down list and store the value selected by the user at runtime, in the context variable,
  • a second tMysqlInput component to generate the information processed by tJavaFlex,
  • a tLogRow component to print the result in the console.

Procedure

  1. Drop a tMysqlInput component and a tJavaFlex component from the Palette onto the design workspace. Connect the two components using a Row > Main link.
  2. Drop a second tMysqlInput component and a tLogRow component from the Palette onto the design workspace. Connect the two components using a Row > Main link. Connect the first subJob to the second using a Trigger > On Subjob Ok connection.
  3. Click the Context tab and define a context variable named named of String type:
  4. Double-click the first tMysql and configure it as in the above example:
    1. add the following query in the query box:
      "select name from employee"
    2. Edit Schema and set this schema.
  5. Click on tJavaFlex to open its Basic settings view and add the following code.
    1. In the Start code box:
      java.util.ArrayList<String> list=new
                                          java.util.ArrayList<String> ();
    2. In the Main code box:
      list.add(row1.name);
    3. In the End code box:
      String [] nameList=new String[list.size()];
                                      nameList=list.toArray(nameList);
                                      JFrame frame = new JFrame("Input Dialog Example");
                                      String returnValue = (String) JOptionPane.showInputDialog(frame,
                                      "Select the name you want to query?","Employee Information",JOptionPane.QUESTION_MESSAGE,null,nameList,nameList[0]);
                                      context.name=returnValue;
  6. In the Advanced Settings panel of tJava, import the full path of the class used in this Job.
  7. Configure the second tMysqlInput component to query the people information from the employee table, and use the tLogRow to print the result in the console, as in the above scenario.
  8. Execute the Job. All the names in the table will be the items of the list as shown below:
  9. For example, select Nicolas from the list. The information related to Nicolas is queried from the table and printed in the console.