| Introduction
For
those of you who have taken the plunge into Web.PB, you know how nice it
is to have the power of PowerBuilder and datastores for creating dynamic web
content. All web applications use some language to create the content
and provide the logic. By coding your logic in Powerscript, you gain all
the power you are accustomed to in regular PowerBuilder applications,
including datastores for database access. Add to that the Web.PB class
library that assists in creating HTML content and session management and
you really a have powerful arsenal.
However,
there is currently no easy way to get data from a datastore translated
into an HTML form or from a form back into a datastore. An HTML form
becomes our editing interface just as datawindows are in PowerBuilder.
Much coding is required to create HTML forms if we create each field of
the form dynamically as needed. This is true despite the fact that the
Web.PB class library provides a wealth of functions to produce almost
any type of web page object.
PB 6.0s
GenerateHTMLForm( )
Powersoft
attempted to alleviate some of the problem by providing a new function
named GenerateHTMLForm() in PowerBuilder 6.0. Unfortunately, this new
feature comes up short on functionality limiting its usefulness to
simple forms.
The
most serious issue is that a while drop-down datawindows get translated
into dropdown list boxes in HTML, the list only contains the single item
present in your main record. Gee, what was the point? Only list box edit
controls with code tables get translated with list data intact.
Other
flaws include the fact that the HTML edit controls include MAXLENGTH but
not SIZE attributes. Also, some datawindow attributes dont get
translated as you might expect.
Even
if the GenerateHTMLForm() function worked as you would expect, the form
creation and display of the data is only half the battle. You still must
create a method that can process the forms data once it gets
submitted. You might think someone could really fill this gap. |
|
Starfire to the
Rescue
Just
when you thought all hope was lost, STEP Consulting comes to the rescue.
Rob Stark and Greg Swanson set out to extend the Web.PB class library to
handle these issues. And handle they did.
They
created the Starfire library. Starfire
started out as a small library to help one of their clients do web
development with PowerBuilder. Since then, it has taken on a life of its
own. If you give it try, youll quickly see why!
The
library dynamically creates HTML forms from datawindows that are fully
editable back to the database, all with very little coding. You can have
a master list that provides hyperlinks that return the detail record in
a form ready for editing. Dropdown datawindows get converted to dropdown
list boxes complete with data. Check boxes and radio buttons are
translated appropriately and even computed columns are handled with
ease. Wow! Imagine leveraging your datawindows right into your Web
applications.
Rob
and Greg did not stop there. The library also translates edit masks and
required attributes into some very clever logic in Javascript. This
javascript is generated right along with your HTML form. Javascript is
often used to provide client-side validation and informs the user of
validation errors before the data gets submitted to your server
application.
The
javascript created by Starfire is tailor made to your datawindow. It
checks for required fields and edits date fields for valid dates and
proper date formatting. In addition, it provides logic to encode the
forms data into a single string to be cleverly passed to a generic
function. This generic function is how Starfire is able to automatically
handle updates to the database from any datawindow form. Without
Starfire, you must manually create a function with arguments that accept
each item from your form, get the data back into the datawindow and
manage the update.
Listing
1 shows how few lines it takes to set up relationship between a list
(master and form detail) relationship. Many options are set with simple
function calls. It could not be much easier to learn or use. |