Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Instantiating and configuring the server component – PB Docs 90 – PowerBuilder Library

Instantiating and configuring the server component – PB Docs 90

Instantiating and configuring the server component

If you are not using the Web DataWindow DTC or the Web Target
object model, you can write code to create an instance of the Web
DataWindow server component, and you can call its methods to create
a Web DataWindow application.

For information on the types of Web DataWindow server components,
see “The Web DataWindow server
component and client control”
. For
information on the Web Target object model and its 4GL extensions,
see Working with Web and JSP Targets
.

Two sets of methods

There
are two sets of methods available on the generic Web DataWindow server
component: methods that are available for other DataWindow controls, and
methods used to configure the component and generate HTML.

DataWindow control methods

DataWindow control methods supported by the generic server
component include sorting, filtering, validation, and get and set
methods. When you call one of these methods on the server component,
the server reloads the page in the browser.

Methods with more than one syntax have a different form for
each syntax to overcome restrictions on the use of overloading.
For example, the ClearValues method takes a string as an argument
and the ClearValuesByColNum method takes a number.

For a complete list of supported DataWindow control methods,
see the DataWindow Reference
or the online
Help.

note.gif Examining server component methods You can view the generic EAServer component methods on the
Components page of the System Tree or in Jaguar Manager. You can
examine the methods in the COM server component in an OLE viewer
(look for PowerBuilder.HTMLDataWindow in the Programmable Objects
list on the OLE tab of the PowerBuilder Browser, or in the Automation
Objects list in the Microsoft OLE/COM Object Viewer).

Configuration and generation methods

Other methods are available to set up the component, retrieve
data, establish persistent values needed by your Web page, and generate
HTML.

If you use a custom server component, there are additional
configuration tasks. For more information, see “Using a custom server component”.

note.gif Mixed case method names The methods of the generic EAServer server component use
mixed case names and all the examples in this section use mixed
case. If you write your own server component, the methods of the
component you generate are all lowercase. (You can use the sample PBDWRMT.PBL as
a starting point if you want the methods described here.) The generic
COM component method names are also all lowercase.

Coding steps

In your server-side script, you will code these tasks:

  1. Instantiate the component.
  2. Load the DataWindow object.
  3. Control what HTML is generated (for example, by
    specifying what functionality to include and what browser to target).
  4. Specify the database connection and retrieve data.
  5. Pass page-specific data to the reloaded page.
  6. Pass user action information to the server component.
  7. Insert the generated HTML in the page template.

Sample code for each of these tasks follows. Most of the code
examples show the DynaScript code you would use to instantiate and
configure the EAServer component. Some ASP examples are provided,
but the code in other ASP server-side scripts would be similar to
the DynaScript examples shown here.

For detailed information about the methods used in the examples,
see the DataWindow Reference
or the online
Help.

Instantiating the component

CreateComponent In PowerDynamo, you use the CreateComponent method of the Java
object to create an instance of the EAServer component. The first
argument is the EAServer package and module name–for
the generic component this is DataWindow/HTMLGenerator100. Additional
arguments specify the URL for the EAServer server and the account
ID and password.

The last argument is necessary only for instantiating a custom
component, described in “Creating a custom server
component in EAServer”
.

This statement creates a component instance called dwMine.
If dwMine is null, the creation fails and the PowerDynamo site object
provides some error information:

CreateObject In ASP, you can access the registered COM component using its
Program ID. For example, if you use the generic component:

Loading the DataWindow object

SetDWObject The next step is to specify
the PBD or PBL file that contains the DataWindow object and the
name of the DataWindow object. You do not need to specify the location
of the file, but it must be available on the component server in
a directory on the server’s path (or on the system path
if the EAServer component is running as a service or if you are
using IIS or MTS):

This DynaScript example tests the return value and writes
an error message to the HTML page (in ASP, use Response.Write instead
of document.Writeln):

You can also specify a:

  • Source definition
    (SRD) file containing the source for a DataWindow object. You can
    export a DataWindow definition to an SRD file in the Library painter or
    System Tree.
  • Powersoft report (PSR) file containing a DataWindow
    object plus data. You can save a PSR file from the DataWindow painter
  • DataWindow Container component on EAServer containing
    multiple DataWindow object definitions

.

For SRD and PSR files, specify an empty string for the DataWindow
name:

For DataWindow Container components, use the the SetDWObjectEx
method:

Controlling what HTML is generated

Disabling features of the client control

SetWeight Although the server component generates a considerable amount of
HTML and JavaScript for the Web DataWindow client control, it is
still no more than an average image file. However, to reduce the
size of the control on the client, you can instruct the component
to leave out code for features you are not using. You can tell the
component to omit code for:

  • Updating data
  • Validating newly entered data
  • Client-side events
  • Allowing client-side scripts to call methods of
    the client control
  • Applying display formats to newly entered data

You can disable any of these on the HTML Generation property
page in the DataWindow painter or with the SetWeight method. False
for a particular argument means no code for that feature is generated.

This statement enables all features:

If updating of data is false, no validation or display formatting
code is generated either. In this statement, it does not matter
what the second and fifth arguments are, because the first argument
for updating data is false:

This statement turns off the client-side scripting capability:

Updating data and display formatting add the most code to
the client-side control. Date processing also generates additional
code. For the smallest client control, turn on only the features
you need and make sure your DataWindow object does not have any
date columns.

Naming the client control

SetHTMLObjectName You need to provide a name for the Web DataWindow client control.
The name is used for page parameters and client-side events. If there
is more than one Web DataWindow client control on the Web page,
each needs a unique name.

This code uses the same name for the server component variable
and the client control:

Optimizing HTML for a browser

SetBrowser The Web DataWindow can generate HTML optimized for particular
browsers and versions. In particular, it can generate code for Microsoft
and Netscape browsers. The browser may be different
each time the server component is instantiated by a different client,
so this information cannot be preset in the DataWindow painter.
You can tell it what browser and version to target in the server-side
script. In the painter, you can set the HTML Version property to
specify what level of HTML to generate if the browser is not recognized.

For information on what HTML features the DataWindow uses
for different browsers, see the DataWindow Reference
or
the HTMLGen.property topic in online Help.

At runtime, the HTTP header sent from the client browser to
the Web server contains the HTTP_USER_AGENT value,
which the server component can use to identify the client browser.

In PowerDynamo, you can use the GetServerVariable method of
the document object to get the HTTP_USER_AGENT
value:

In ASP, you can use the ServerVariables method of the Request
object to get the HTTP_USER_AGENT value:

Specifying the database connection and retrieving data

Specifying connection information

SetTrans You provide connection information for the server component
with the SetTrans method. The arguments you specify depend on the
type of connection. For an ODBC connection to Adaptive Server Anywhere
6.0, you specify all the connection information in the dbParm argument.

In EAServer, you must also set up a connection cache for
the component, described in “Creating a connection cache
on EAServer “
.

The data source must be defined on the server machine. It
must be a system DSN on EAServer if the component is running as
a service, and it must always be a system DSN on MTS or IIS. This statement connects to the
EAS Demo DB sample database:

note.gif Using Adaptive Server Enterprise PowerBuilder and EAServer use slightly different versions
of the CT-Lib software to connect to Adaptive Server Enterprise
via Open Client. In the PowerBuilder development environment, you
use the SYC native database interface to connect to the database,
but you must use SYJ as the first argument to SetTrans to connect
to ASE in EAServer.

Retrieving data

Retrieve To tell the server component to retrieve data, you call the
Retrieve method or, if the DataWindow object expects retrieval arguments,
the RetrieveEx method.

This DynaScript code calls Retrieve and, if the return value
reports an error, calls GetLastErrorString for the error message
text. In ASP, use Response.Write instead of document.Writeln:

Specifying retrieval arguments

RetrieveEx If the DataWindow
object expects retrieval arguments, call RetrieveEx:

Typically, the retrieval arguments are not constants. They
are page parameters passed to the page from another page where the
user filled in a form or clicked a hyperlink. If the DataWindow
expects more than one retrieval argument, the arguments must be
passed in a single string. The arguments in the string must be separated
by newline characters (
), and individual values cannot
contain newline characters as part of the value. Array values must
be separated by tab characters ( ).

Values passed into the page are properties of the value property
of the document object. For example, this form prompts the user
for a salary:

In the PowerDynamo server-side script in salaryrpt.stm, code
calls the RetrieveEx method for the server component using the salary
value passed as a page parameter:

Getting the retrieval argument from another page works the
first time the page is loaded. The retrieval arguments have to be
page parameters each time the page is reloaded. To specify page
parameters for the reloaded page, you use the SetSelfLink method,
described next.

Passing page-specific data to the reloaded page

Using self link information

The first time the client browser requests the page template,
it can pass page-specific information using GET or POST, and the
page can use those values in the server-side scripts. However, when
the page is reloaded because of user interactions with the Web DataWindow,
that information is not passed to the page automatically.

To make the information available, you specify a selflinkargs string
with values that become page parameters in the reloaded page. Typically,
you would use self-link parameters to keep available:

  • Login information from another page
  • The DataWindow object name
  • Retrieval arguments for the DataWindow object

To provide these values when the page is reloaded, you use
the SetSelfLink method, which takes as arguments the URL of the
page template as well as the selflinkargs string.

Getting the URL for the page

To reload the page correctly in response to user actions,
the server component needs to know the URL of the page template.
You can get this information from the name property of the document
object or the SCRIPT_NAME server variable.

In PowerDynamo, use the GetServerVariable method of the document
object:

In ASP, use the ServerVariables method of the Request object:

Building a self-link argument string

Self-link arguments become page parameters in the reloaded
page. Your script typically looks at an existing page parameter
and re-creates it using a self-link argument. The syntax for specifying
a self-link argument string is:

The string can contain one or more page parameter and expression
pairs separated by pipes ( | ). Each expression is a DataWindow
expression that evaluates to a string. Usually you specify constant
string values that are already values of page parameters rather
than expressions.

The expression is enclosed in quotes, and if the value is
a constant, it must also be enclosed in quotes. For example, if
a page parameter called logname is passed to the page and it has
the value Fred, the string you need to pass in the SetSelfLink method
is:

To get the value from the current logname parameter, which
is already defined for the page, you build the expression using
the logname page parameter. The single quotes and inner double quotes
are embedded in the expression. The current value of logname is
inserted between the quotes:

An expression does not need the inner quotes:

Passing the URL and argument string to SetSelfLink

SetSelfLink Use the URL obtained from the SCRIPT_NAME server
variable and the link arguments string you built as arguments to
the SetSelfLink method:

Retrieval arguments as self-link values

The first time the page is loaded, the retrieval argument
might be:

  • A page parameter passed from another
    page. The user might have clicked a URL that included the value
    or filled in a form that posted the value.
  • A new value calculated in the current script.

If the value is a page parameter, then you can re-create the
page parameter using SetSelfLink. If the value is from some other
source, you need to write code that gets the value from the source
(which might be a page parameter) the first time the page is loaded
and from a page parameter when it is reloaded.

Examples

These PowerDynamo examples show code that works with the types
of values listed above. They illustrate how to get each type of
value and use it in both RetrieveEx and SetSelfLink method calls.

Value from another page If the user entered a product ID in a form to get detailed
information on the product, the product ID is passed to the product report
template as a page parameter. The page parameter should always exist because
it comes from the calling page, but the code provides a default
value anyway:

Calculated value If the value is to be calculated in the script, then the page parameter
will not exist the first time the script runs. If the random page parameter
exists, the script gets the value from the parameter; otherwise
the script calculates a value using a Math function:

Multiple values In this example, a Web page with a form prompts the user for a
user name and a product category and the level of detail the user
wants to see. The code uses the product category as a retrieval
argument for the Web DataWindow. The script selects a DataWindow
object based on the level of detail. All three values are carried
over each time the page is reloaded:

Passing user actions to the server component

SetAction When the user clicks a DataWindow button, action information
is passed back to the page server as context and action page parameters.
Your server-side script needs to access those page parameters and
call SetAction so the server component can apply the action to the
generated HTML.

The names of the parameters use the object name specified
in the SetHTMLObjectName method, for example: dwMine_action
and dwMine_context. You can also specify the object name
on the HTML Generation tab page in the DataWindow painter:.

You can include buttons for scrolling to other pages of data
and for retrieving and updating data and inserting and deleting
rows. When these button actions occur, the change is sent back to
the server component and the change is made in the DataWindow buffer.
If the user clicks an update button, the update method is called
in the component without any other scripting needed.

note.gif No need to call methods You can call server component methods directly for retrieving
data, updating, inserting and deleting rows, and so forth. However,
remember that button clicks invoke the actions. You do not need
to call the methods too.

This DynaScript code uses a function called GetParam to see
if the parameters have been defined (meaning that the page is a
reloaded page) and if so, calls SetAction to send the action information
to the server component:

Inserting the generated HTML into the page

Generate After the server script has done all the setup, it calls the
Generate function, which returns the generated HTML as a string.

In PowerDynamo, use document.Write to insert the code in the
page template:

In ASP, use Response.Write to insert the code in the page
template:


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x