ASNA WingsRPG™ Reference Manual

Replacing a DdsCharField with Radio Buttons

Wings uses an ADO DataSet to pass formatted data between the RPG program and the display file ASPX page. You can make a fairly easy UI embellishment where you need to have access to this data. From the ASPX code behind, you can know whether data is being marshaled from the RPG program to the web server or from the web server back to the RPG program.

The display file DataSet is composed of as many tables as there are record formats in the display file. If there is at least 1 row in the table, then Wings knows that the format has been written by the RPG program. If a table (i.e., record format) in the DataSet has no rows, then the format was not written by the RPG logic.

The data fields in each table correspond to the Monarch controls (fields) defined in the corresponding record format.

There are two overridable methods in ASNA.Monarch.Page that process the data to and from the web page:

  • OnCopyDspFileToBrowser - This method populates the record format controls and the fields within for each table that has 1 or more rows.
  • OnCopyBrowserToDspFile - This method populates the table rows from the active record format controls and their fields to be returned to the RPG program.

How to override the OnCopy... methods

This is the basic structure for overriding these methods in AVR.NET (this would look similar in C# or VB.NET):

Begsr OnCopyBrowserToDspFile Access(*Protected) Modifier(*Overrides)

	*Base.OnCopyBrowserToDspFile()

Endsr

Begsr OnCopyDspFileToBrowser Access(*Protected) Modifier(*Overrides)

	*Base.OnCopyDspFileToBrowser()

Endsr

Note the call to the base class method. This is important because the base method still does all the marshaling to and from the ASPX page.

Simple Example: How to populate a field using radio buttons

In this example, we have a record format called "CUSTREC" containing a field named SFYN01 that has two expected values, "Y" and "N":

This is the look and behavior we want to achieve with radio buttons:

Here are the ID and Alias properties of this Wings DdsCharField control that are key to working in the code behind:

Although we want to replace this entry field with radio buttons, we cannot remove the control from the page, since the control defines the field used by the RPG program. In other words, if the control was removed, there would no longer be a field in the CUSTREC format called "SFYN01 ".

What we do, instead, is to move the field to a convenient, but out of the way, location in the format, make it invisible at runtime, and then replace it visually with radio buttons. In this case, we'll use the standard ASP RadioButtonList control (ID=rdoSendConfirmation). The RadioButtonList Items property allows easy design-time maintenance of the ListItems that comprise the button options (in this case Text=Yes & No; Values = Y & N).

The figures below illustrate these steps:


Drag and drop the DdsCharfield in an out of the way spot in Visual Studio's Design View.

In the properties window, Set the DdsCharfield's VisibleCondition Property to *False, hiding it from end users.

Select a RadioButtonList control from the toolbox, and drag and drop it into position.

Add Members for Yes and No to the radiobuttonlist control.

Here is the code behind to initialize the radio button value and to transfer the selected value back into the SFYN01 field:

// Work with values to/from Monarch DdsCharField control

Begsr OnCopyDspFileToBrowser Access(*Protected) Modifier(*Overrides)

	*Base.OnCopyDspFiletoBrowser()	// 1st Assign data to controls
	If *this.Dspf.DataSet.Tables["CUSTREC"].Rows.Count > 0	// CUSTREC active format?
		rdoSendConfirmation.SelectedValue = CUSTREC_SFYN01.Value	// give radio button value to select
	Endif

Endsr

Begsr OnCopyBrowserToDspfFile Access(*Protected) Modifier(*Overrides)

	If *this.Dspf.DataSet.Tables["CUSTREC"].Rows.Count > 0	// CUSTREC active format?
		CUSTREC_SFYN01.Value = rdoSendConfirmation.SelectedValue	// get button selection into Dds Field
	Endif

	// Important:  This step must follow above since data is in the control
	*Base.OnCopyBrowserToDspFile()	// Transfer control values to Dspf.dataset

Endsr

Caution — The above code works just fine as long as SFYN01 contains exactly "Y" or "N". Any other characters, including lower case "y" and "n" will raise an exception. This can be resolved as illustrated below and it also demonstrates how the integrity of an IBM i application can be improved without actually modifying the legacy RPG ILE code.

// Work with values to/from Monarch DdsCharField control

Begsr OnCopyDspFileToBrowser Access(*Protected) Modifier(*Overrides)
	dclfld Work type(*string)

	*Base.OnCopyDspFiletoBrowser()	// 1st Assign data to controls
	If *this.Dspf.DataSet.Tables["CUSTREC"].Rows.Count > 0	// CUSTREC active format?
		Work = CUSTREC_SFYN01.Value.ToUpper()
		If ( Work <> "Y" ) & ( Work <> "N" )	//ensure either Y or N
			Work = "N"
		Endif
		rdoSendConfirmaton.SelectedValue = Work	// give radio button value to select
	Endif

Endsr

It is not necessary to use the data values from Wings controls exclusively. We can also work directly with the field values of the DataTable row. Note in the OnCopyBrowserToDspFile code below where the placement of the call to the base method is important.

// Work with values to/from Display File DataSet	
Begsr OnCopyDspFileToBrowser Access(*Protected) Modifier(*Overrides)
	dclfld Work type(*string)
	dclfld dt   type( System.Data.DataTable )

	If *this.Dspf.DataSet.Tables["CUSTREC"].Rows.Count > 0	// CUSTREC active format?
		dt = *this.DspF.DataSet.Tables["CUSTREC"]				// for easier reading
		Work = dt.Rows[0].Item["SFYN01"].ToString()				// get field content from row
		If ( Work <> "Y" ) & ( Work <> "N" )	// ensure either Y or N
			Work = "N"
		Endif
		rdoSendConfirmaton.SelectedValue = Work					// give radio button value to select
	Endif

Endsr

Begsr	OnCopyBrowserToDspFile Access(*Protected) Modifier(*Overrides)
	dclfld dt type( System.Data.DataTable )

	*Base.OnCopyBrowserToDspFile()		// Transfer control values to DspF.DataSet

	// Important.  This step must follor above since we want to retain altered table contents
	If *this.DspF.DataSet.Tables["CUSTREC"].Rows.Count > 0	// CUSTREC active format
		dt = *this.DspF.DataSet.Tables["CUSTREC"]				// for easier reading
		dt.Rows[0].Item["SFY01"] = rdoSendConfirmation.SelectedValue  // get button selection into DataSet
	Endif
Endsr