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:

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:

pageparam1=’expr1’|pageparam2=’expr2’...|pageparamn=’exprn

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:

String logname = (String)    request.getParameter("Logname");
String linkargs = 
		"logname='\"" + logname + "\"'";

An expression does not need the inner quotes:

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:

dwGen.SetSelfLink(pageName, linkargs);

Retrieval arguments as self-link values

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

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:

String prod_id;
prod_id=(String) request.getParameter("ProdID"); 
if (prod_id == null){
   prod_id = "1";
}
dwGen.RetrieveEx(prod_id);
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:

// Get product category as a retrieval arg
String retrievearg, username, rptlevel, dw;
retrievearg =     (String)request.getParameter("category");
if (retrievearg == null) {
retrievearg = "all";
}
int rtn = dwGen.RetrieveEx(retrievearg);
if (rtn < 0) {
	... // Check for error
}
// Get the user name
username =(String)request.getParameter("username");
if (username	 != null){
out.print("<P>Dear " + username + "</P>");
}
out.print("<P>Here is the report you
	requested.</P>");

// Choose DW based on detail level requested
rptlevel=(String)request.getParameter("reportlevel");
if (rptlevel == "detail"){
	dw = "d_product_detail";
} else if (rptlevel == "summary"){
	dw = "d_product_summary";
} else {
	dw = (String) request.getParameter("dw");
	if (dw == null} {
	out.print ("<P>Error selecting report");
	//handle error or halt processing ...
}
dwGen.SetDWObject("productrpt.pbd", dw);

// Tell the server component to recreate the 
// page parameters generated for the browser
String linkargs = "username='\"" + username + "\"'"
 + "|category= '\"" + retrievearg + "\"'"
 + "|dw= '\"" + dw + "\"'";

dwGen.SetSelfLink( pageName, linkargs );