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.
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.
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:
1 |
<span>pageparam1</span>='<span>expr1</span>'|<span>pageparam2</span>='<span>expr2</span>'...|<span>pageparam</span><span>n</span>='<span>expr</span><span>n</span>' |
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:
1 |
String logname = (String)    request.getParameter("Logname"); |
1 |
String linkargs = |
1 |
"logname='"" + logname + ""'"; |
An expression does not need the inner quotes:
1 |
String linkargs = "date='String(Today())'"; |
Passing the URL and argument string to SetSelfLink
SetSelfLink
Use the URL and the link arguments string as arguments to
the SetSelfLink method:
1 |
dwGen.SetSelfLink(pageName, linkargs); |
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 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:
1 |
String prod_id; |
1 |
prod_id=(String) request.getParameter("ProdID"); |
1 |
if (prod_id == null){ |
1 |
   prod_id = "1"; |
1 |
} |
1 |
dwGen.RetrieveEx(prod_id); |
1 |
dwGen.SetSelfLink( "ProdID=" + "'"" + prod_id + ""'"); |
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:
1 |
// Get product category as a retrieval arg |
1 |
String retrievearg, username, rptlevel, dw; |
1 |
retrievearg =     (String)request.getParameter("category"); |
1 |
if (retrievearg == null) { |
1 |
retrievearg = "all"; |
1 |
} |
1 |
int rtn = dwGen.RetrieveEx(retrievearg); |
1 |
if (rtn < 0) { |
1 |
... // Check for error |
1 |
} |
1 |
// Get the user name |
1 |
username =(String)request.getParameter("username"); |
1 |
if (username != null){ |
1 |
out.print("<P>Dear " + username + "</P>"); |
1 |
} |
1 |
out.print("<P>Here is the report you<br> requested.</P>"); |
1 |
1 |
// Choose DW based on detail level requested |
1 |
rptlevel=(String)request.getParameter("reportlevel"); |
1 |
if (rptlevel == "detail"){ |
1 |
dw = "d_product_detail"; |
1 |
} else if (rptlevel == "summary"){ |
1 |
dw = "d_product_summary"; |
1 |
} else { |
1 |
dw = (String) request.getParameter("dw"); |
1 |
if (dw == null} { |
1 |
out.print ("<P>Error selecting report"); |
1 |
//handle error or halt processing ... |
1 |
} |
1 |
dwGen.SetDWObject("productrpt.pbd", dw); |
1 |
1 |
// Tell the server component to recreate the |
1 |
// page parameters generated for the browser |
1 |
String linkargs = "username='"" + username + ""'" |
1 |
+ "|category= '"" + retrievearg + ""'" |
1 |
+ "|dw= '"" + dw + ""'"; |
1 |
1 |
dwGen.SetSelfLink( pageName, linkargs ); |