Skip to main content Skip to complementary content

Creating a dynamic drop-down list

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 view 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.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!