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 100 – PowerBuilder Library

Instantiating and configuring the server component – PB Docs 100

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

Two
sets of methods are available on the generic Web DataWindow server component:

  • Methods that are available for other DataWindow
    controls
  • 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 EAServer 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 some of these tasks follows. For detailed
information about the methods used in the examples, see the DataWindow
Reference

or the online Help.

Instantiating the component

JSP targets If you are not using the jspobject100.jar object
model, you instantiate a Web DataWindow component in the following
manner:

ASP targets 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 COM+):

You can test the return value for and write an error message
to the HTML page in a JSP target with the following code:

You could use similar code in an ASP target:

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 is generated

Disabling features of the client control

SetWeight Although the server component generates a considerable amount of
HTML or XHTML 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 Web 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:

note.gif XML Web DataWindow If you are using an XML Web DataWindow with a custom XHTML
template, the object name in the template must match the name of
the client control (dw_1 in the example).

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 might 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 User-Agent or HTTP_USER_AGENT
value, which the server component can use to identify the client
browser.

In JSP, you call the getHeader method of the request object
to get the 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,
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 COM+. This statement connects to the EAS Demo DB sample
database:

If you are using the XML Web DataWindow, it is best to call
the SetPageSize method to limit the number of rows per page:

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 when the DataWindow object
does not have retrieval arguments, you call the Retrieve method:

This ASP code calls Retrieve and, if the return value reports
an error, calls GetLastErrorString for the error message text:

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 ( ).

This example form prompts the user for a salary:

Code in server-side script in salaryrpt.jsp can then call
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 header or the SCRIPT_NAME server variable.

In JSP, you must parse the return value from a request.getRequestURI
call:

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 has the value Johnson, the
value of the expression must be enclosed in two sets of quote marks: ‘”Johnson”‘

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 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 and the link arguments string 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 JSP 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:

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: dw_1_action
and dw_1_context. You can also specify the object
name on the Web 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 JSP code checks whether 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 or XHTML 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 JSP, use out.print to insert code in the page template:

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

GenerateXHTML and GenerateXMLWeb In JSP targets, you return the Web DataWindow in XHTML with
the GenerateXHTML command:

The GenerateXMLWeb method generates the content, layout, style,
and client-side functionality of the DataWindow separately
in XML, XSLT, CSS, and JS files. It returns the browser-specific
XSLT transformation script that uses the generated files to render
the DataWindow in XHTML on the client side:


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