Featured Post

Applying Email Validation to a JavaFX TextField Using Binding

This example uses the same controller as in a previous post but adds a use case to support email validation.  A Commons Validator object is ...

Sunday, March 27, 2011

Component Field TEXT in Talend Open Studio

A textbox is a versatile way to gather parameters for a custom component in Talend Open Studio.  To create a textbox for the custom component, specify a PARAMETER element with a FIELD of "TEXT".

In the Component View, a textbox is used to extract a free-form text value from the user.

The following is a list of attributes that can be set on a textbox parameter.

  • FIELD.  For a textbox, this is "TEXT".
  • NAME.  A unique name for the textbox.  Used in the begin, main, and end Javajet files.
  • NUM_ROW.  Row position of the components.  If used in more than one component, more than one UI control will appear in the same row.
  • REQUIRED.  Displays an asterisk ("*") next to the textbox.  Will flag an error if parameter is not provided when run.
  • SHOW_IF.  An expression that toggles the display of textbox.
  • READONLY.  The textbox is not editable. 
  • DEFAULT.  A child element containing text initially displayed when the component is put on the canvas 
The expression loaded in a SHOW_IF is based on a Talend scripting implementation that uses parenthesis, equality operators, and boolean logic.  The equality operators are "==" and "!=", just like in Java.  The boolean logic operators are "and" and "or", not like in Java.  When comparing against a constant, use single quotes.  There is also a NOT_SHOW_IF that inverts the logic.

DEFAULT is a child element (not an attribute) that can contain a text string to be displayed when the component is first put on the canvas.  If the DEFAULT is overwritten by saving a value from the Component View, you'll need to create another component to see the DEFAULT value again.

READONLY will make the textbox not editable.  There are variations READONLY_IF and NOT_READONLY_IF that will make the textbox uneditable if a condition is met as in SHOW_IF.  The condition is in the JavaScript-styled Talend scripting implementation.

XML Descriptor
 
 Here is a list of sample values from the XML descriptor rendered in the Component Designer perspective.

Values for 3 FIELD=TEXT PARAMETERS
Component View
 
The display of the sample values is in the following tab.

Display of 3 FIELD=TEXT PARAMETERS
The screenshot shows three parameters: P1, P2, and P3.  P2 has REQUIRED set to true.  This marks it with the asterisk which will throw an error if run without a value.  "Show P3?" is checked which controls the display of P3.

Code
 
The following is a sample Java JET main that prints the variable values.

<%
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
INode node = (INode)codeGenArgument.getArgument();
String cid = node.getUniqueName();


String param1 = ElementParameterParser.getValue(node, "__PARAM1__");
String param2 = ElementParameterParser.getValue(node, "__PARAM2__");


String showp3_s = ElementParameterParser.getValue(node, "__SHOW_P3__");
Boolean showp3 = new Boolean(showp3_s);


String param3 = ElementParameterParser.getValue(node, "__PARAM3__");
%>


System.out.println("p1=<%= param1 %>");
System.out.println("p2=<%= param2 %>");


if( <%= showp3_s %> ) {
  System.out.println("p3=<%= param3 %>");
}

The textbox is a flexible way to gather input from the user to configure a component.  NUM_ROWS controls the position of the textbox in the Component View.  SHOW_IF and REQUIRED show/hide and validate the textbox.

No comments:

Post a Comment