[Perl-widget-developer] Teambuilding Exercise #2: Usage
Status: Alpha
Brought to you by:
spadkins
From: Stephen A. <ste...@of...> - 2001-06-05 19:53:08
|
Hi, We have gotten pretty focused over the last 24 hours on guts. I am still working my teambuilding plan, which recognizes that debating the guts is engaging, but it is the last step. This exercise is about defining the usage of widgets. I present here two files. cgi-bin/cgisample a CGI script using widgets cgi-bin/cgisample.xml a configuration file for widgets used Note: These two files are running code in CVS. See http://www.officevision.com/cgi-bin/pub/Widget/cgisample I would encourage others to post sample CGI scripts, templates, and config files that suggest how *they* would like to use widgets. Forget the internals for a moment. ;-) Stephen P.S. I agree with Cees's comments about improving DateDropDowns. shark:/usr/ov/acoc/dev/src/Widget/cgi-bin> more cgisample cgisample.xml :::::::::::::: cgisample :::::::::::::: #!/usr/local/bin/perl -w ############################################################## # cgisample ############################################################## # This is an example of a CGI script that uses the capabilities # of the Perl Widget Library minimally. # It looks like any other perl script which uses the CGI.pm # library. # See 'wexec' for an example of a CGI script that uses # the full capabilities of the Perl Widget Library. ############################################################## use lib "/usr/ov/acoc/dev/src/Widget"; use CGI; $query = new CGI; use Widget; $wc = Widget->controller(-cgi => $query); $wc->process_request(); print <<EOF; Content-type: text/html <head> <title>cgisample</title> </head> <body bgcolor=#ffffff> <h1>cgisample</h1> <hr> <form method='POST'> EOF # Please note that there is *nothing* in this code which indicates what physical # class is used to render each "logical" widget. # When the widget is instantiated, though, it is a physical one. # The controller decided which physical widget it would be based on configuration # information and runtime information (not yet implemented) # There's more than one way to do it... ;-) $first_name = $wc->widget("first_name")->html(); # you can skip the widget and just get its HTML $last_name = $wc->widget("last_name")->html(); $address = $wc->widget( -name => "address", -class => "Widget::HTML::Element", -tag => 'input', -type => 'text', -size => '14', -maxlength => '99', )->html(); $birth_dt = $wc->widget("birth_dt")->html; # of course, you don't need to provide parentheses ... $sex = $wc->widget("sex")->html(); $w_check_it = $wc->widget("check_it"); # or you can get the widget $check_it = $w_check_it->html(); # then get its HTML $anniv_dt = $wc->widget("anniv_dt")->html(); $anniv_dt_value = $wc->widget("anniv_dt")->value(); # you can also do other things to a widget, like get its value # note that $wc caches widget instances, so the previous two lines did use the same physical widget $anniv_dt_value = "" if (!defined $anniv_dt_value); print <<EOF; <table border=0> <tr> <td>First Name: </td><td>$first_name</td> <td>Widget::HTML::Element - a general widget for constructing any HTML element (remember, only the configurer worries about what physical class it is. It's transparent to the programmer)</td> </tr> <tr> <td>Last Name: </td><td>$last_name</td> <td>Widget::HTML::Element</td> </tr> <tr> <td>Birth Date: </td><td>$birth_dt</td> <td>Widget::HTML::Element</td> </tr> <tr> <td>Address: </td><td>$address</td> <td>Widget::HTML::Element (not in config file)</td> </tr> <tr> <td>Sex: </td><td>$sex</td> <td>Widget::HTML::Select</td> </tr> <tr> <td>Anniversary Date: </td><td>$anniv_dt</td> <td>Widget::HTML::DateDropDowns</td> </tr> <tr> <td> </td><td>$check_it</td> <td>Widget::HTML::Button</td> </tr> <tr> <td>Anniversary Date is ... </td><td>$anniv_dt_value</td> <td> (value) </td> </tr> </table> </form> </body> </html> EOF :::::::::::::: cgisample.xml :::::::::::::: <config> <widget name="first_name" tag='input' type='text' size='14' maxlength='99'/> <widget name="last_name" widget-class='Widget::HTML::Element' tag='input' type='text' size='14' maxlength='99'/> <widget name="birth_dt" widget-type='date'/> <widget name="anniv_dt" widget-type='date3'/> <widget name="anniv_dt.year" widget-type='year'/> <widget name="anniv_dt.month" widget-type='month'/> <widget name="anniv_dt.day" widget-type='day'/> <widget name="sex" widget-type='sex'/> <widget name="check_it" widget-type='check_anniv_dt'/> <widget-type name="date" tag='input' type='text' size='14' maxlength='99'/> <widget-type name="date3" widget-class='Widget::HTML::DateDropDowns'/> <widget-type name="sex" widget-class='Widget::HTML::Select' domain='sex'/> <widget-type name="year" widget-class='Widget::HTML::Select' domain='year'/> <widget-type name="month" widget-class='Widget::HTML::Select' domain='month'/> <widget-type name="day" widget-class='Widget::HTML::Select' domain='day'/> <widget-type name="check_anniv_dt" widget-class='Widget::HTML::Button' label=' Check Your Anniversary Date '/> <domain name="sex"> <item name="M" label="Male"/> <item name="F" label="Female"/> </domain> <domain name="year"> <item name="1980"/> <item name="1981"/> <item name="1982"/> <item name="1983"/> <item name="1984"/> <item name="1985"/> <item name="1986"/> <item name="1987"/> <item name="1988"/> <item name="1989"/> <item name="1990"/> <item name="1991"/> <item name="1992"/> <item name="1993"/> <item name="1994"/> <item name="1995"/> <item name="1996"/> <item name="1997"/> <item name="1998"/> <item name="1999"/> <item name="2000"/> <item name="2001"/> <item name="2002"/> <item name="2003"/> <item name="2004"/> <item name="2005"/> <item name="2006"/> <item name="2007"/> <item name="2008"/> <item name="2009"/> </domain> <domain name="month"> <item name="01" label="Jan"/> <item name="02" label="Feb"/> <item name="03" label="Mar"/> <item name="04" label="Apr"/> <item name="05" label="May"/> <item name="06" label="Jun"/> <item name="07" label="Jul"/> <item name="08" label="Aug"/> <item name="09" label="Sep"/> <item name="10" label="Oct"/> <item name="11" label="Nov"/> <item name="12" label="Dec"/> </domain> <domain name="day"> <item name="01"/> <item name="02"/> <item name="03"/> <item name="04"/> <item name="05"/> <item name="06"/> <item name="07"/> <item name="08"/> <item name="09"/> <item name="10"/> <item name="11"/> <item name="12"/> <item name="13"/> <item name="14"/> <item name="15"/> <item name="16"/> <item name="17"/> <item name="18"/> <item name="19"/> <item name="20"/> <item name="21"/> <item name="22"/> <item name="23"/> <item name="24"/> <item name="25"/> <item name="26"/> <item name="27"/> <item name="28"/> <item name="29"/> <item name="30"/> <item name="31"/> </domain> </config> |