There has been some discussion on the list lately about generating widgets
ala CGI.pm, HTML::StickyWidgets etc...
The thing is that these products or plug-ins are very HTML oriented. The
widget is defined as an HTML widget like a textfield or checkbox or
dropdown or what-have-you.
What I am really looking for is a library that abstracts and allows widgets
to be developed that are tied to an application not to a set of HTML
necessarily. I guess I will start by providing an example of what I want
based on what we currently do in our Java framework when he use Templating
there. I'd like it if someone has developed the same thing in Perl that we
could reuse, otherwise, we may need to write this.
A widget should be a plugin or tag that may be embedded in a template with
the definition of that widget tied to some APPLICATION-LEVEL piece of data
entry not at the HTML-LEVEL.
For example,
<TR>
<TH>First Name:</TH><TD><widget id="fname"/></TD>
<TH>Last Name:</TH><TD><widget id="lname"/></TD>
<TH>Comments</TH><TD><widget id="comments"/></TD>
</TR>
As you can see the basic idea is that the <widget> tag (or it could be Perl
object embedded in the template) is actually *intelligent*.
It should be configured as a Perl object that knows that an fname is a
textfield and an lname is a textfield and a comments field is a text area.
And if I change my mind and decide that comments is better off as a
textfield, I should not have to change any templates that use the <widget
id="comments"/> tag.
Now, HTML::StickyWidgets and CGI.pm could be used by a true widget
abstraction library to generate HTML widgets. But what I want to do is
provide the capability of also abstracting even higher. Like at the data level.
I forsee a
WidgetCollection class which holds widgets together
Widget class that provides the interface to what a widget does
and Widget::XXXX subclasses that provide definitions relevant to the widget
types used on the forms.
Where HTML::StickyForms comes in is something like
Widget::HTML::TextField
Widget::HTML::TextArea
Widget::HTML::CheckBox
etc...
This is extensible as we provide more cross platforms ones can be added as
Widget::WML::TextField
Widget::WML::CheckBox
And it support intelligence...
Widget::HTML::Date is a widget that would actually contain a drop down for
month, a drop down for day and a drop down for year parts of a Date.
But the widget object itself can set and get it's data as a Date string.
In other words, the nice thing about a generic Widget library is that you
can start easy (aka HTML::StickyWidgets) but you can end up with a library
of common tags that many applications require.
I believe such a library of widget plug-ins could be made semi-indepenent
of the templating language used with perhaps plugin wrappers for each one
(In particular I am interested in TemplateToolkit).
The way these widgets would be configured is something like the following
my $widget_collection = new WidgetCollection(
-WIDGET_FORM_DATA => $CGI , # (CGI.pm object)
-WIDGET_HASH =>
'fname' => new Widget(-TYPE => HTML::TextField, -NAME=> "fname"....)
'lname' => new Widget(-TYPE => HTML::TextField, -NAME=> 'lname'....),
'birthday' => new Widget(-TYPE => HTML::Date, -DAY_NAME => "dob_day"....)
)
Then if I want to get a widget...I can say
my $widget = $widget_collection->getWidget('fname');
By default the widget object data is set using the CGI.pm object (or
Apache::Request)
But you can manually get and set the data...
print $widget->get_value();
or
$widget->set_value("gunther");
In the case of a date widget... you can do something like
$widget->set_value("5/22/2001"); if the format defined in the constructor
of the date widget was "5/22/2001" for mm/dd/yyyy
And most importantly, widgets know how to display themselves...
print $fname_widget->display(); prints the HTML text field
whereas
print $date_of_birth_widget->display(); prints the three drop downs that
represents the month day and year.
Of course, the widget library could be expanded by the open source
community. For example, I can imagine a date widget that also has a button
that says "Click for Calendar"... and then a javascript popup comes up with
a mini-calendar for selecting the date.
Does anyone have a widget framework like this? I think the closest I found
to widget abstraction is SmartWorker, but it is not abstract in quite the
way that I want above.
What I want is a business or application context widget that can be
configured on-the-fly to be something other than a plain HTML widget. After
using this concept in our Java toolkit for 6 months, I find the abstraction
to be quite useful and really want to have the same feature in Perl.
Has someone done this already?
Thanks,
Gunther