| |
Populate a drop-down list from a file in an mrc Servlet application. |
| by Margaret Jeronim |
|
|
By now you probably already know how to populate a drop-down list from a file in Web/CGI maintenance applications. But, what about doing the same in Web/Servlets? The technique for doing so is similar to the one in Web/CGI, and it is done via a call to an external object.
The mrc-Productivity Series includes a powerful template that allows you to create Java external objects (R8 (Web/Servlet) External Object Inquiry) to use with mrc servlets.
This template includes a few JAVA functions that allow it to create different external objects. By specifying different function names during the method of defining external objects in option 44 of mrc, you can accomplish a variety of things: from record level security to population of a drop-down list. For a list of available functions please visit the Servlet User Guide.
The following example shows how to populate a state field, so you will display the state name for the user to select, but write to the file state abbreviation - In this case, display Illinois, write IL. In order to populate this drop-down list from a file you will need the following:
1. Database file that contains two fields: 'State Code' and 'State Name'. In this example 'State Code' is defined as a 2 character alphanumeric field and 'State Name' as a 30 character alphanumeric field. You can use the mrc maintenance application to create the file if you don't have one in your system.
2. Create a retrieval application using the file you've created in step 1. Sequence it by the 'State Code' field. In option 7, Client/Server options, flag 'Create retrieval Client/Server' to 'O' (This indicates that you only want to create a browser version of this application). Select R8 (Web/Servlet) External Object Inquiry as the Application type. Compile your retrieval. By using this template, you've just created a Java external object.
3. Now, define your created retrieval as an external object in option 44 of mrc. See Figure 1 for details on defining this external object.
 Figure 1 (click image to enlarge)
You will notice that the definition for this external object is different. Its Object type is defined as M (method). Class/Exec represents the location of your retrieval (DataDictionary.IXXXXXs) where Data Dictionary is the dictionary where you've created your external object (retrieval) and IXXXXXs is your retrieval number. (This is the standard naming convention for mrc. The 's' indicates that this application is a servlet).
Method is defined as 'getSelect("Select State", pName, pValue, "select", 1)' . getSelect is a function that is defined in the template source. It requires parameters that are defined within the parenthesis . "Select State" will be displayed as the first line in the drop down box. You can specify any text you would like to use, but make sure you've included it within double quotes ("").
pName and pValue are required, and are defined names within the 'getSelect' function definition in the template source. "Select" indicates that you want to create a drop-down list. Or, you can specify "radio" and get radio buttons. 1 indicates that you're listing one item per line.
Classpath/path is defined as '/mrcjava/WEB-INF/classes/.' and is the location on your IFS where the retrieval is located. NOTE: All mrc generated servlets are located in the /mrcjava/WEB-INF/classes/data dictionary. The Object name can be anything you want as long as that name does not already exist.
4. After defining the external object you will also need to define one parameter for this external object. It is needed to pass data from the file into the external object. This parameter is going to be a 2 character alphanumeric field that is equal to 'State Code'. It is a required parameter. The parameter field name is going to be equal to the physical field name of 'State Code' (STATEC in this case, see figure 2 for defining the parameter for this external object).
 Figure 2 (click image to enlarge)
5. After defining your external object, you can use it in any maintenance application. You will call it from option 8 - External Objects and pass the field containing the state code to it. Make sure that you use the *SELECT for the template location for this external object call. You will then be able to display the name of the state but write only the abbreviation of that state to the file. (See figure 3 for a maintenance application with a populated drop-down list using an external object).
 Figure 3 (click image to enlarge)
NOTE: See figure 4 for defining this external object to display 3 radio buttons across the line and figure 5 for the result of calling such object in maintenance application.
 Figure 4 (click image to enlarge)
 Figure 5 (click image to enlarge)
|
|
 |
mrc publishes this newsletter on a monthly basis. Subscription is free of charge. Please send any questions or comments about this newsletter to news@mrc-productivity.com. This newsletter is edited by Heather Gately.
To unsubscribe, please just reply to this e-mail with Unsubscribe in the subject line.
View our privacy promise.
|
 |
|