The Velocity template context contains an object that can be referenced as $las_config. This is an instantiation of the LASConfig object in the Product Server. Studying the JavaDoc for this object is the only way to get a complete understanding what information is available and what methods can be used to get at the information, but this document will offer some examples to get you started. More examples can be found in the Template Snippets.
Example 1: Getting Data set and Variable Information.
Suppose you'd like to have a menus of the all the variables in the data sets that were in the original request. The first job is to extract the list of data sets and variables IDs that were in the request. The $las_request the instantiation of the LASUIRequest object (a JDOM document version of the xml= query parameter for the request that is producing this output). To extract the data sets IDs used in the request, use the $las_request.getDatasetsIDs() (or if you want to get fancy with the Velocity syntax you can abbreviate this as $las_request.datasetsIDs). Now with that information you can extract the full dataset objects the config object. So, putting it all together, here's a list of all the datasets used in the request, with a pull down menu of the variables. Often there is only one variable in a request, so all the looping becomes superfluous, but it's necessary just in case there's more than one.
$las_config.getVariables
To be honest, in order to get this example to work the way I wanted to I had to create the getDataset(String ID) method in the LASConfig object. There had been no need to get just one data set previously. The methods is 7 lines of code. I say all this to underscore that sometimes it's simple to do something on the server-side to make things a whole lot easier on the client side. So if you don't see a method to get exactly what you need, let's create one. Here's how it works now, with some comments to help you figure out what's going on.
<ul> ## Get the list of data sets IDs for the variables ## that were in the request. There will be one data set ID ## for each variable, even if the variables are in the same ## data set. #set($dsets = $las_request.datasetIDs) ## Loop over the data set IDs. #foreach($id in $dsets) ## Get a Dataset config object for the dataset (this allows ## access to all its characteristics (like it name). #set($ds = $las_config.getDataset($id)) ## Put the name of the data set on the page. <li>Data set: $ds.name <ol> ## Use the data set ID to get the sibling ## variables #foreach ($var in $las_config.getVariables($id)) <li> Variable: $var.name with ID = $var.ID</li> #end </ol> </li> #end </ul>
This loop would produce the following in the page created by the template.
- Data set: COADS climatology
- Variable: AIR TEMPERATURE with ID = airt
- Variable: SPECIFIC HUMIDITY with ID = speh
- Variable: SEA SURFACE TEMPERATURE with ID = sst
- Variable: ZONAL WIND with ID = uwnd
- Variable: WIND SPEED with ID = wspd
- Variable: MERIDIONAL WIND with ID = vwnd
- Variable: SEA LEVEL PRESSURE with ID = slp
Of course, you probably don't want to create a list, you probably want to build a pull-down menu or some other form element so the user can interact with the information.
Example 2: Getting the Constraints associated with a variable.
For some data sets (particularly those stored in databases) the user interface must allow users to add additional constraints to the data selection that is used to create the product. For example, when selecting SST observations from a data set, the user might want to select only those values above a certain threshold or data from a particular cruise.
In order to allow these selections the LAS installer adds the definitions to the configuration information. In order to discover them and display them as part of an output template you will use a technique similar to the example above. To get started you'll need to extract the same information from the $las_request (the data set and variable IDs). Then you can ask for any Constraint objects that are associated with those data set and variable ID pairs. From the Constraint object you can build the form elements you need for the user to interact with the constraints. Here's a table with the constraints displayed. There are comments in the text to help you figure out what's going on. [Note: we should build a macro for this since this is fairly complicated and might be a popular thing to do.]
<form> ## ## Grab the data set and variable ids #set($ids = $las_request.getDatasetIDs()) #set($varids = $las_request.getVariableIDs()) ## Loop the data set ids #foreach ($id in $ids) ## Grab the corresponding variable ID #set($idx = $velocityCount - 1) #set($varID = $varids.get($idx)) ## Get the constraints from the configuration #set($cons = $las_config.getConstraints($id, $varID)) ## Loop the constraints #foreach ($con in $cons) ## Get the menu values for the left-hand side, the operations ## and the right-hand side #set($lhs = $con.getLhs()) #set($ops = $con.getOps()) #set($rhs = $con.getRhs()) <table border="2"> <tr> <th>Left-hand Side Menu Values</th> <th> Operations </th> <th> Right-hand side </th> </tr> <tr> <td> ## Make a drop down menu for the LHS <select name="constraint_$idx"> #set($pairs = $lhs) #foreach( $pair in $pairs ) <option value="$pair.value">$pair.name</option> #end </select> </td> <td> ## Same for the operations <select name="constraint_$idx"> #set($pairs = $ops) #foreach ($pair in $pairs) <option value="$pair.getValue()">$pair.getName()</option> #end </select> </td> <td> ## If there are menu items in the RHS make a menu. #if ( $rhs.size() > 0 ) <select name="constraint_$idx"> #set($pairs = $rhs) #foreach($pair in $pairs) <option value="$pair.value">$pair.name</option> #end </select> #else ## If there are no menu items, make a text entry box. ## This will be the case for variable constraints <input type="text" size="12" name="constraint_$idx_text"/> #end </td> </tr> </table> #end #end </form>
Adding this to the top of the output template produces a table similar to the one shown below.
|
These are two examples of configuration you can extract from your data set configuration. You can also get property values and any other information from the configuration and use it in you output template by using the methods in LASUIRequest and LASConfig.