Binding data to DataWindow retrieval arguments
The
Web DataWindow DTC can bind data from the current page or a linking page
as values for retrieval
arguments, allowing you to control what data is retrieved. You can
use retrieval arguments to allow a single page to retrieve different
sets of data depending on a user’s selection, or to enable
the reuse of a single DataWindow object in designing many pages.
To use retrieval arguments, you define them when you create
the DataWindow object in PowerBuilder or InfoMaker. You make the
retrieval arguments part of the WHERE clause for the SQL statement.
Then, when you select the DataWindow object for your Web DataWindow,
the retrieval arguments you defined are automatically listed in
the Argument Name column on the Retrieval tab of the Sybase Web
DataWindow DTC Properties dialog box.
You can have the following types of binding for your retrieval
arguments, depending on whether or not your DataWindow Web page
is 4GL enabled:
Binding type | 4GL enabled | Not 4GL enabled |
---|---|---|
Constants | Yes | Yes |
Control Values | Yes | No, but you can use page parameters to bind control values (sent in a form submit or query string) to retrieval arguments |
JavaScript Expressions | Yes, but not available for JSP targets | Yes, but not available for JSP targets |
Page Parameters | Yes, but the parameter you bind must be on the list of parameters in the Page Properties dialog box |
Yes |
Page Variables | Yes | No |
Constants
Use
a constant when the retrieval argument is always the same in the
particular page you are designing. You specify the value directly
on the Retrieval tab of the Sybase Web DataWindow DTC Properties
dialog box.
Example
Using a constant This example has a single page called emplist.htm in
the Massachusetts section of your site. The DataWindow object has
a retrieval argument called “state”, which allows you to use the
same DataWindow object on other pages that list employees by state.
On the Retrieval page of the Sybase Web DataWindow DTC Properties
dialog box, you can type MA as a constant value for the state retrieval
argument.
JavaScript Expressions
Use
a JavaScript expression when the retrieval argument value requires processing
before the DataWindow retrieves data. You can include variables that
have been defined in another script on the same page in your JavaScript expression.
Binding a retrieval argument to a JavaScript expression is not possible
in a JSP target.
To use a variable, you must declare the variable in a server
script that runs before the Web DataWindow DTC. On 4GL Web pages,
you can do this by adding variables to a data table on the Variables
page of the Page Properties dialog box. The dialog box then generates
the declaration script for you.
Verify in the Source view You can look at the page in Source view to make sure scripts
appear on the page in the right order.
Example 1
Using a JavaScript variable In this example, a server script establishes the value of
the State retrieval argument. In the script, which must be executed before
the DataWindow scripts on the page, the variable currstate is
assigned a value. The script can do any other processing that you
need.
1 |
var currstate = "MA"; |
On the Retrieval page of the Sybase Web DataWindow DTC Properties
dialog box, specify currstate as a JavaScript
expression for the state retrieval argument.
Example 2
Using an expression In this example, a server script on a login confirmation page
for employees created a Userid property for the psSession object.
The value was passed to the confirmation page as a page parameter.
1 |
psSession.SetValue("Userid",<br /> psDocument.GetParam("loginid")); |
On some other page in the Web application, a Web DataWindow
DTC can use the Userid value by specifying this expression on the
Retrieval tab.
1 |
psSession.GetValue("Userid") |
Page Parameters
Use a page
parameter when the value for the retrieval argument is specified
on another page. You can add page parameters on the Parameters tab
page of the Page Properties dialog box. The parameters you specify
automatically appear in the Bind Value drop-down list on the Retrieval
tab of the Sybase Web DataWindow
DTC Properties dialog box when you select Page Parameters as the
bind type.
For 4GL Web pages When the linking page is 4GL enabled, the Web Target user
interface lets you specify parameters (and variables, expressions,
and so on) to pass to the target page using different navigation
styles: Hyperlink, Form Submit, or Server Redirect. After you link
these values to parameters that you specify on a target page containing
a Web DataWindow, you can select the parameters from the Bind Value
drop-down list to bind them to your retrieval arguments.
For more information on navigation styles for 4GL pages, see “Setting up page navigation”.
For non-4GL Web pages When the linking page is not 4GL enabled, you can use the
Hyperlink or the Form Submit navigation styles, but you must manually
edit or verify the source code yourself rather than rely on the
Web Target user interface to generate this for you. The following
table shows the tasks required on the linking page to submit a value
as a parameter for a retrieval argument on the target page.
Navigation style | Tasks on linking page |
---|---|
Hyperlink | Set HREF attribute for the A element to the target URL. Append a page parameter to the URL using a query string |
Form Submit | Make sure all controls (whose values you want to bind to the retrieval argument on a target page) are wrapped in a FORM element. Set the ACTION attribute of the FORM element to the target URL |
On the Retrieval tab of the Sybase Web DataWindow DTC (in
the target page), select Page Parameter as the bind type and type
in the parameters you are passing in the Bind Value column. The
parameters you type must match the parameters you submit from the
linking page.
For more information about page parameters, see “Managing page data”.
Example 1
Setting up and using a page parameter In this example, the user selects a state and views a list
of employees in that state. Two Web pages are involved: the linking
page has a form for selecting the state and the target page has
a Web DataWindow DTC. This example demonstrates one way to pass
page parameters from a linking page that is not 4GL enabled.
The first page, Empstate.htm, includes
this form:
1 |
<FORM id=FORM1 name=EmployeeState action="emplist.htm"<br /> method=post> <br /> Choose a state:<br /> <SELECT id=SELECT1 name=State size=3> <br /> <OPTION value=MA>Massachusetts <br /> <OPTION value=CA>California <br /> <OPTION value=TX>Texas<br /> </SELECT> <br /> <INPUT value=Go id=INPUT1 name=Submit type=submit><br /> </FORM> |
When the user clicks the button labeled Go, the target page Emplist.htm displays. Emplist.htm has
two page parameters with names that match the two form fields: State
and Submit.
In the Web DataWindow DTC, the DataWindow object has a retrieval argument
called “state”. On the Retrieval tab of the Properties dialog box,
you make the connection between the state retrieval argument, which
is listed automatically, and the State page parameter.
The names of the form field and the target page parameter
must match in capitalization. In the form above, the NAME attribute
of the SELECT element is State; therefore, the page parameter name
in the Bind Value column must also be State, with the same capitalization.
Example 2
Page parameters passed from <A> elements An alternative to the Form Submit method is a list of hyperlinks.
On the linking page Empstate.htm, several HTML
anchor elements could include a query string as part of the target
URL. In each anchor element, the query string assigns a different
value to the name State.
1 |
<LI><A id=A1 href="emplist.htm?State=MA"><br /> Massachusetts</A></LI><br /> <LI><A id=A2 href="emplist.htm?State=CA"><br /> California</A></LI><br /> <LI><A id=A3 href="emplist.htm?State=TX"> <br /> Texas</A></LI> |
Page Variables
Use
a page variable when the value you want to bind to a retrieval argument
is specified in a variable on the same page as the Sybase Web DataWindow
DTC. You can set page or session variables for the retrieval argument
only on 4GL-enabled Web pages.
Control Values
Use
a control when the value you want to bind to the retrieval argument
is specified in a server-scriptable control on the same page as
the Web DataWindow DTC. You can set a server-scriptable control
value for a retrieval argument on a 4GL-enabled Web page only.