SlideShare a Scribd company logo
1 of 11
Rational Host Access Transformation Services
Tutorial: Custom Widget
Abstract
Transformation is the core function of HATS. Components and Widgets provide important functions in
transformation process. Once components are recognized in specified regions of the host screen, widgets
render these regions. HATS offers settings for the provided components and widgets to handle most
conditions. You can also modify settings at the project level, in the rendering sets, or in a specific
transformation.
If you would like to render host components in a special way (such as combining two lines of data to one
line) and the provided HATS widgets cannot be configured to meet your requirement, writing your own
custom widget could be a way to resolve this condition. This tutorial is designed for a web developer who
would like to know how to create a custom widget.
Topics covered in this tutorial
This tutorial will cover how to create a screen customization that sets global variables, and give instruction
on how to construct a custom widget. In this tutorial, the scenario we will use is creating a HTML custom
widget containing an input field and a button. The widget we will create in this tutorial can be used when a
host screen contains the host component that would be recognized as an Input field or an Input field with
hints and a web developer wants to use an additional button to send mnemonic keyword for a specific
purpose:
Example:
A Help button, to send the mnemonic keyword [pf1]
A Prompt button, to send the mnemonic keyword [pf4]
The button name and mnemonic keyword can be:
 Inputted from the widget settings
 Imported from specified global variables
Assumptions
This tutorial assumes:
 You have already installed HATS Toolkit v7.1.
 You are already familiar with basic HATS skills to customize HATS applications, to use global
variables and to perform running on server.
 The HATS toolkit is open, and a HATS project exists in your workspace.
Create your custom widget
The widget java file is a Java class which determines how this widget will behave. In this tutorial, we
describe widget creation steps with a HATS Web project. To create the widget in HATS RCP project, the
steps are almost the same.
For more information about required elements of a widget, refer to the section Creating custom
components and widgets in Web Application Programmer’s Guide or Rich Client Platform Programmer’s
Guide.
The scenario that we are going to use in this demo is:
A web developer would like to create a custom widget to transform Input field and Input field with hints
components. By using this widget, the web developer offers users an additional button beside the input field
so that users could use this button for specific purpose. Additionally, the web developer prefers the user uses
those buttons instead of function keys.
Now we will look at steps to create and use this widget:
1. To create the widget, go to your HATS Web project and launch the Create a Widget wizard by right
clicking your HATS project -> New -> Widget. In the Create a Widget wizard, enter a name for the
widget (we use MyCustomWidget as the widget’s name in this tutorial), ensure the checkbox Include
methods to allow settings to be modified in the HATS Toolkit checked, and associate this widget
with the component Input field and Input field with hints. The screen will look like:
When Include methods to allow settings to be modified in the HATS Toolkit option is enabled,
additional methods getPropertyPageCount(),getCustomProperties() and getDefaultValues() will be
appended to the new Java source file for further implementation.
2. After the wizard is finished, the Java source file MyCustomWidget.java in your HATS Web project
should be created in the directory widgets as shown below:
3. Open MyCustomWidget.java with the Java Editor. You will see that some of the elements have been
constructed in this source file. We are now ready to implement the code for the widget:
4. According to our design, the widget settings should have the following capabilities:
 To retrieve the button name and mnemonic keyword from global variables if the checkbox Fill
from global variables is checked
 To retrieve the button name and mnemonic keyword from an input string if the checkbox Input
directly is checked.
 To treat the button name and mnemonic keyword as an empty string if there is a conflict.
Note: The following screen shot shows the widget settings that will be created after the widget
implementation completed.
4.1 To achieve this goal, we use the public method getCustomProperties() to implement the GUI for
widget settings.
Add this method to MyCustomWidget.java and append appropriate GUI components into it. The
code blocks includes declarations for the properties and statements to create GUI components as
shown below:
 Declarations for the properties:
 Statements to create GUI components:
For detailed information about how to customize widget settings, refer to the HATS Information
Center and HATS API References.
4.2 Once the code block in section 4.1 is created, you can verify the widget settings. Go to Navigator
view -> Web Content -> and open the component and widget list file, ComponentWidget.xml.
You will find that the new widget MyCustomWidget is registered to the component and widget
list:
And the widget is associated to components Input field and Input field with hints as shown
below:
Go to your project settings and verify the new GUI. Ensure all GUI elements behave properly.
5. After coding the widget settings, it is time to define how this widget will render the associated
components. The public method, drawHTML(), is one of required methods of a Web widget.
drawHTML() is used to generate HTML output in JSP files in a HATS Web project. For a HATS RCP
project, you can use another public method drawSWT() to generate RCP output.
In drawHTML(), you need to complete following steps from 5.1 to 5.7:
5.1 Examine the following code that generated by the wizard. In the code block, the buffer is used to
store generated HTML, and the HTML element factory will create HTML elements:
5.2 Declare variables to store settings:
In this step, you might experience compile errors for missing imports. You can use Source ->
Organize Imports to resolve the missing imports. .
5.3 In the next step, we will use the public class
com.ibm.hats.transform.elements.InputComponentElement to generate HTML input
elements. The code block will iterate through each componentElements object. Please note that
the widget should not process components that have already been processed by a HATS global
rule. The method RenderingRulesEngine.processMatchingElement() will return the
transformation fragment if this input field has been processed, or return NULL if it is not
processed yet. For more information about widgets and global rules, refer to the section Creating
custom components and widgets in Web Application Programmer’s Guide or Rich Client
Platform Programmer’s Guide.
Add the code block below:
5.4 Add the button element next to the input field and use getContextAttribute() to extract the hash
table for global variables:
These statements above are to determine how to set the button name and mnemonic keyword. We
use the following three methodologies here:
1. If only Fill from global variables is checked and global variables are available,
extract values from global variables.
2. If only Input directly is checked, extract values from widget settings.
3. If the GUI configuration is incorrect, set button name and mnemonic keyword to
empty string.
5.5 Get button name and mnemonic keyword from global variables or widget settings:
5.51 Scenario 1: Get from global variables:
5.52 Scenario 2: Get from widget settings:
5.6 The last step is to set button name, mnemonic keyword and action for this button:
6. At this point, we have completed the implementation of this widget. To test obtaining the button label
and host key mnemonic from global variables, we need to initialize those two global variables by
creating a screen customization with set global variable actions. This step is only for demonstration
purpose in this tutorial. You need to consider when to set these two global variables and how to set
them to match your business needs.
6.1 Create a HATS Customization with the name CustomSignOn.evnt. Apply the transformation
default.jsp to the customization CustomSignOn.evnt. Add two Actions to set these two global
variables to the customization CustomSignOn. The page Actions in CustomSignOn.evnt looks
like :
With this design, the customization CustomSignOn.evnt will initialize values for button name and
mnemonic keyword when host connection established.
For more information about the available mnemonic keywords, refer to The HATS-supported
3270 mnemonic keyword table and The HATS-supported 5250 mnemonic keyword table in
Enabling keyboard support.
6.2 In this tutorial, the custom widget is associated with Input field and Input field with hints,
which are used to transform un-protected field like the input field Position to type in System i
screen Work with Objects Using PDM. You can navigate to the screen Work with Objects
Using PDM by: signing on to your System i and issuing the command STRPDM in the
command line. It will look like:
In the green screen, end users need to know that if they position their cursor in the Position to type
field, they can press PF1 to receive help information for that field. See the help dialog below:
To achieve this goal, create a HATS Transformation, WorkWithObjectsUsingPDM. Use
MyCustomWidget widget for the input field Position to type and use field components and
widgets for the other regions of this screen:
Edit this host component of this input field. Configure widget settings as shown below:
7. Save all changes in your HATS web project.
It’s time to test functionalities for this new widget. Perform Run on Server or Debug on Server to test
it, ensuring that the widget behaves properly in each condition.
Conclusion
This tutorial has demonstrated how to use HATS Toolkit to create and test a custom widget. The option
to create your own custom widgets is very helpful when the settings that are provided by HATS do not
meet your needs. Using this powerful capability could help you to reduce the effort when customizing a
large number of host screens.
Related References
See Web Application Programmer’s Guide and Rich Client Platform Programmer’s Guide for more
information.

More Related Content

What's hot

LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
Akhil Mittal
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
Faina Fridman
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
Krazy Koder
 
android layouts
android layoutsandroid layouts
android layouts
Deepa Rani
 
Creating Workflows Windows Share Point Services
Creating Workflows Windows Share Point ServicesCreating Workflows Windows Share Point Services
Creating Workflows Windows Share Point Services
LiquidHub
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1
Akhil Mittal
 

What's hot (15)

Module 4: Introduction to ASP.NET 3.5 (Material)
Module 4: Introduction to ASP.NET 3.5 (Material)Module 4: Introduction to ASP.NET 3.5 (Material)
Module 4: Introduction to ASP.NET 3.5 (Material)
 
Responsive Design and Bootstrap
Responsive Design  and BootstrapResponsive Design  and Bootstrap
Responsive Design and Bootstrap
 
CIC_Manual.pdf
CIC_Manual.pdfCIC_Manual.pdf
CIC_Manual.pdf
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
GWT Training - Session 1/3
GWT Training - Session 1/3GWT Training - Session 1/3
GWT Training - Session 1/3
 
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
230394452 extending-extending-srm-web-dynpro-view srm-web-dynpro-view
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
 
Rc085 010d-vaadin7
Rc085 010d-vaadin7Rc085 010d-vaadin7
Rc085 010d-vaadin7
 
android layouts
android layoutsandroid layouts
android layouts
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
 
Creating Workflows Windows Share Point Services
Creating Workflows Windows Share Point ServicesCreating Workflows Windows Share Point Services
Creating Workflows Windows Share Point Services
 
Diving into VS 2015 Day1
Diving into VS 2015 Day1Diving into VS 2015 Day1
Diving into VS 2015 Day1
 

Viewers also liked (10)

Putovanje u putopis,vida ognjenović pitanja
Putovanje u putopis,vida ognjenović pitanjaPutovanje u putopis,vida ognjenović pitanja
Putovanje u putopis,vida ognjenović pitanja
 
Advanced macro guide
Advanced macro guideAdvanced macro guide
Advanced macro guide
 
P01 source-book1-hatsv6 pot-customer_solutions
P01 source-book1-hatsv6 pot-customer_solutionsP01 source-book1-hatsv6 pot-customer_solutions
P01 source-book1-hatsv6 pot-customer_solutions
 
Hats guia de_macro
Hats guia de_macroHats guia de_macro
Hats guia de_macro
 
201505 Gear - Bankportaal
201505 Gear - Bankportaal201505 Gear - Bankportaal
201505 Gear - Bankportaal
 
Entorno personal de aprendizaje (ple)
Entorno personal de aprendizaje (ple)Entorno personal de aprendizaje (ple)
Entorno personal de aprendizaje (ple)
 
Getstart
GetstartGetstart
Getstart
 
Lectura de palabras con RR
Lectura de palabras con RRLectura de palabras con RR
Lectura de palabras con RR
 
σχολικές πρακτικές για την καλλιέργεια θετικού κλίματος
σχολικές πρακτικές για την καλλιέργεια θετικού κλίματοςσχολικές πρακτικές για την καλλιέργεια θετικού κλίματος
σχολικές πρακτικές για την καλλιέργεια θετικού κλίματος
 
Practica 15.Empresas de intermediacion
Practica 15.Empresas de intermediacionPractica 15.Empresas de intermediacion
Practica 15.Empresas de intermediacion
 

Similar to Hats tutorial custom widget

Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docx
hanneloremccaffery
 
SoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentizationSoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentization
Nicolas Fränkel
 
Text Component FeaturesThe JTextComponent class is the foundation .pdf
Text Component FeaturesThe JTextComponent class is the foundation .pdfText Component FeaturesThe JTextComponent class is the foundation .pdf
Text Component FeaturesThe JTextComponent class is the foundation .pdf
aquadreammail
 
Devoxx 09 (Belgium)
Devoxx 09 (Belgium)Devoxx 09 (Belgium)
Devoxx 09 (Belgium)
Roger Kitain
 

Similar to Hats tutorial custom widget (20)

Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web Murach : How to develop a single-page MVC web
Murach : How to develop a single-page MVC web
 
Foundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docxFoundation and PathwaysCOS10020 Creating Web Application.docx
Foundation and PathwaysCOS10020 Creating Web Application.docx
 
Parallelminds.web partdemo
Parallelminds.web partdemoParallelminds.web partdemo
Parallelminds.web partdemo
 
Streamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptxStreamlining React Component Development and Sharing with bit.pptx
Streamlining React Component Development and Sharing with bit.pptx
 
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
ChircuVictor StefircaMadalin rad_aspmvc3_wcf_vs2010
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookies
 
SoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentizationSoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentization
 
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
Nagios Conference 2013 - Jake Omann - Developing Nagios XI Components and Wiz...
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
03 asp.net session04
03 asp.net session0403 asp.net session04
03 asp.net session04
 
Selectionwidgetwhitepaper 140907120000-phpapp02
Selectionwidgetwhitepaper 140907120000-phpapp02Selectionwidgetwhitepaper 140907120000-phpapp02
Selectionwidgetwhitepaper 140907120000-phpapp02
 
15 asp.net session22
15 asp.net session2215 asp.net session22
15 asp.net session22
 
Text Component FeaturesThe JTextComponent class is the foundation .pdf
Text Component FeaturesThe JTextComponent class is the foundation .pdfText Component FeaturesThe JTextComponent class is the foundation .pdf
Text Component FeaturesThe JTextComponent class is the foundation .pdf
 
Devoxx 09 (Belgium)
Devoxx 09 (Belgium)Devoxx 09 (Belgium)
Devoxx 09 (Belgium)
 
PPT1
PPT1PPT1
PPT1
 
Enhancements
Enhancements Enhancements
Enhancements
 
Implementation procedure of OPNET, and Qualnet
Implementation procedure of OPNET, and QualnetImplementation procedure of OPNET, and Qualnet
Implementation procedure of OPNET, and Qualnet
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAMWSO2Con2024 - Organization Management: The Revolution in B2B CIAM
WSO2Con2024 - Organization Management: The Revolution in B2B CIAM
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in UgandaWSO2CON 2024 - Building a Digital Government in Uganda
WSO2CON 2024 - Building a Digital Government in Uganda
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Hats tutorial custom widget

  • 1. Rational Host Access Transformation Services Tutorial: Custom Widget Abstract Transformation is the core function of HATS. Components and Widgets provide important functions in transformation process. Once components are recognized in specified regions of the host screen, widgets render these regions. HATS offers settings for the provided components and widgets to handle most conditions. You can also modify settings at the project level, in the rendering sets, or in a specific transformation. If you would like to render host components in a special way (such as combining two lines of data to one line) and the provided HATS widgets cannot be configured to meet your requirement, writing your own custom widget could be a way to resolve this condition. This tutorial is designed for a web developer who would like to know how to create a custom widget. Topics covered in this tutorial This tutorial will cover how to create a screen customization that sets global variables, and give instruction on how to construct a custom widget. In this tutorial, the scenario we will use is creating a HTML custom widget containing an input field and a button. The widget we will create in this tutorial can be used when a host screen contains the host component that would be recognized as an Input field or an Input field with hints and a web developer wants to use an additional button to send mnemonic keyword for a specific purpose: Example: A Help button, to send the mnemonic keyword [pf1] A Prompt button, to send the mnemonic keyword [pf4] The button name and mnemonic keyword can be:  Inputted from the widget settings  Imported from specified global variables Assumptions This tutorial assumes:  You have already installed HATS Toolkit v7.1.  You are already familiar with basic HATS skills to customize HATS applications, to use global variables and to perform running on server.  The HATS toolkit is open, and a HATS project exists in your workspace. Create your custom widget The widget java file is a Java class which determines how this widget will behave. In this tutorial, we
  • 2. describe widget creation steps with a HATS Web project. To create the widget in HATS RCP project, the steps are almost the same. For more information about required elements of a widget, refer to the section Creating custom components and widgets in Web Application Programmer’s Guide or Rich Client Platform Programmer’s Guide. The scenario that we are going to use in this demo is: A web developer would like to create a custom widget to transform Input field and Input field with hints components. By using this widget, the web developer offers users an additional button beside the input field so that users could use this button for specific purpose. Additionally, the web developer prefers the user uses those buttons instead of function keys. Now we will look at steps to create and use this widget: 1. To create the widget, go to your HATS Web project and launch the Create a Widget wizard by right clicking your HATS project -> New -> Widget. In the Create a Widget wizard, enter a name for the widget (we use MyCustomWidget as the widget’s name in this tutorial), ensure the checkbox Include methods to allow settings to be modified in the HATS Toolkit checked, and associate this widget with the component Input field and Input field with hints. The screen will look like: When Include methods to allow settings to be modified in the HATS Toolkit option is enabled, additional methods getPropertyPageCount(),getCustomProperties() and getDefaultValues() will be appended to the new Java source file for further implementation. 2. After the wizard is finished, the Java source file MyCustomWidget.java in your HATS Web project should be created in the directory widgets as shown below:
  • 3. 3. Open MyCustomWidget.java with the Java Editor. You will see that some of the elements have been constructed in this source file. We are now ready to implement the code for the widget:
  • 4. 4. According to our design, the widget settings should have the following capabilities:  To retrieve the button name and mnemonic keyword from global variables if the checkbox Fill from global variables is checked  To retrieve the button name and mnemonic keyword from an input string if the checkbox Input directly is checked.  To treat the button name and mnemonic keyword as an empty string if there is a conflict. Note: The following screen shot shows the widget settings that will be created after the widget implementation completed. 4.1 To achieve this goal, we use the public method getCustomProperties() to implement the GUI for widget settings. Add this method to MyCustomWidget.java and append appropriate GUI components into it. The code blocks includes declarations for the properties and statements to create GUI components as shown below:  Declarations for the properties:
  • 5.  Statements to create GUI components: For detailed information about how to customize widget settings, refer to the HATS Information Center and HATS API References. 4.2 Once the code block in section 4.1 is created, you can verify the widget settings. Go to Navigator view -> Web Content -> and open the component and widget list file, ComponentWidget.xml. You will find that the new widget MyCustomWidget is registered to the component and widget list: And the widget is associated to components Input field and Input field with hints as shown below: Go to your project settings and verify the new GUI. Ensure all GUI elements behave properly.
  • 6. 5. After coding the widget settings, it is time to define how this widget will render the associated components. The public method, drawHTML(), is one of required methods of a Web widget. drawHTML() is used to generate HTML output in JSP files in a HATS Web project. For a HATS RCP project, you can use another public method drawSWT() to generate RCP output. In drawHTML(), you need to complete following steps from 5.1 to 5.7: 5.1 Examine the following code that generated by the wizard. In the code block, the buffer is used to store generated HTML, and the HTML element factory will create HTML elements: 5.2 Declare variables to store settings: In this step, you might experience compile errors for missing imports. You can use Source -> Organize Imports to resolve the missing imports. . 5.3 In the next step, we will use the public class com.ibm.hats.transform.elements.InputComponentElement to generate HTML input elements. The code block will iterate through each componentElements object. Please note that the widget should not process components that have already been processed by a HATS global rule. The method RenderingRulesEngine.processMatchingElement() will return the transformation fragment if this input field has been processed, or return NULL if it is not processed yet. For more information about widgets and global rules, refer to the section Creating custom components and widgets in Web Application Programmer’s Guide or Rich Client Platform Programmer’s Guide. Add the code block below:
  • 7. 5.4 Add the button element next to the input field and use getContextAttribute() to extract the hash table for global variables: These statements above are to determine how to set the button name and mnemonic keyword. We use the following three methodologies here: 1. If only Fill from global variables is checked and global variables are available, extract values from global variables. 2. If only Input directly is checked, extract values from widget settings. 3. If the GUI configuration is incorrect, set button name and mnemonic keyword to empty string. 5.5 Get button name and mnemonic keyword from global variables or widget settings: 5.51 Scenario 1: Get from global variables:
  • 8. 5.52 Scenario 2: Get from widget settings: 5.6 The last step is to set button name, mnemonic keyword and action for this button: 6. At this point, we have completed the implementation of this widget. To test obtaining the button label and host key mnemonic from global variables, we need to initialize those two global variables by creating a screen customization with set global variable actions. This step is only for demonstration purpose in this tutorial. You need to consider when to set these two global variables and how to set them to match your business needs. 6.1 Create a HATS Customization with the name CustomSignOn.evnt. Apply the transformation default.jsp to the customization CustomSignOn.evnt. Add two Actions to set these two global variables to the customization CustomSignOn. The page Actions in CustomSignOn.evnt looks like : With this design, the customization CustomSignOn.evnt will initialize values for button name and mnemonic keyword when host connection established. For more information about the available mnemonic keywords, refer to The HATS-supported 3270 mnemonic keyword table and The HATS-supported 5250 mnemonic keyword table in Enabling keyboard support.
  • 9. 6.2 In this tutorial, the custom widget is associated with Input field and Input field with hints, which are used to transform un-protected field like the input field Position to type in System i screen Work with Objects Using PDM. You can navigate to the screen Work with Objects Using PDM by: signing on to your System i and issuing the command STRPDM in the command line. It will look like: In the green screen, end users need to know that if they position their cursor in the Position to type field, they can press PF1 to receive help information for that field. See the help dialog below:
  • 10. To achieve this goal, create a HATS Transformation, WorkWithObjectsUsingPDM. Use MyCustomWidget widget for the input field Position to type and use field components and widgets for the other regions of this screen: Edit this host component of this input field. Configure widget settings as shown below: 7. Save all changes in your HATS web project. It’s time to test functionalities for this new widget. Perform Run on Server or Debug on Server to test it, ensuring that the widget behaves properly in each condition.
  • 11. Conclusion This tutorial has demonstrated how to use HATS Toolkit to create and test a custom widget. The option to create your own custom widgets is very helpful when the settings that are provided by HATS do not meet your needs. Using this powerful capability could help you to reduce the effort when customizing a large number of host screens. Related References See Web Application Programmer’s Guide and Rich Client Platform Programmer’s Guide for more information.