File: app.html

package info (click to toggle)
picolisp 3.1.0.7-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,100 kB
  • sloc: ansic: 14,205; lisp: 795; makefile: 290; sh: 13
file content (2560 lines) | stat: -rw-r--r-- 97,013 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/1998/REC-html40-19980424/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PicoLisp Application Development</title>
<link rel="stylesheet" href="doc.css" type="text/css">
</head>
<body>
<a href="mailto:abu@software-lab.de">abu@software-lab.de</a>

<h1>PicoLisp Application Development</h1>

<p align=right>(c) Software Lab. Alexander Burger

<p>This document presents an introduction to writing browser-based applications
in PicoLisp.

<p>It concentrates on the XHTML/CSS GUI-Framework (as opposed to the previous
Java-AWT, Java-Swing and Plain-HTML frameworks), which is easier to use, more
flexible in layout design, and does not depend on plug-ins, JavaScript or
cookies.

<p>A plain HTTP/HTML GUI has various advantages: It runs on any browser, and can
be fully driven by scripts ("@lib/scrape.l").

<p>To be precise: CSS <i>can</i> be used to enhance the layout. And browsers
<i>with</i> JavaScript will respond faster and smoother. But this framework
works just fine in browsers which do not know anything about CSS or JavaScript.
All examples were also tested using the w3m text browser.

<p>For basic informations about the PicoLisp system please look at the <a
href="ref.html">PicoLisp Reference</a> and the <a href="tut.html">PicoLisp
Tutorial</a>. Knowledge of HTML, and a bit of CSS and HTTP is assumed.

<p>The examples assume that PicoLisp was started from a global installation (see
<a href="ref.html#inst">Installation</a>).

<p><ul>
<li><a href="#static">Static Pages</a>
   <ul>
   <li><a href="#hello">Hello World</a>
      <ul>
      <li><a href="#server">Start the application server</a>
      <li><a href="#how">How does it work?</a>
      </ul>
   <li><a href="#urlSyntax">URL Syntax</a>
   <li><a href="#security">Security</a>
      <ul>
      <li><a href="#pw">The ".pw" File</a>
      </ul>
   <li><a href="#htmlFoo">The <code>html</code> Function</a>
   <li><a href="#cssAttr">CSS Attributes</a>
   <li><a href="#tags">Tag Functions</a>
      <ul>
      <li><a href="#simple">Simple Tags</a>
      <li><a href="#lists">(Un)ordered Lists</a>
      <li><a href="#tables">Tables</a>
      <li><a href="#menus">Menus and Tabs</a>
      </ul>
   </ul>
<li><a href="#forms">Interactive Forms</a>
   <ul>
   <li><a href="#sessions">Sessions</a>
   <li><a href="#actionForms">Action Forms</a>
      <ul>
      <li><a href="#guiFoo">The <code>gui</code> Function</a>
      <li><a href="#ctlFlow">Control Flow</a>
      <li><a href="#switching">Switching URLs</a>
      <li><a href="#dialogs">Alerts and Dialogs</a>
      <li><a href="#calc">A Calculator Example</a>
      </ul>
   <li><a href="#charts">Charts</a>
      <ul>
      <li><a href="#scrolling">Scrolling</a>
      <li><a href="#putGet">Put and Get Functions</a>
      </ul>
   </ul>
<li><a href="#guiClasses">GUI Classes</a>
   <ul>
   <li><a href="#inputFields">Input Fields</a>
      <ul>
      <li><a href="#numberFields">Numeric Input Fields</a>
      <li><a href="#timeDateFields">Time &amp; Date</a>
      <li><a href="#telFields">Telephone Numbers</a>
      <li><a href="#checkboxes">Checkboxes</a>
      </ul>
   <li><a href="#fieldPrefix">Field Prefix Classes</a>
      <ul>
      <li><a href="#initPrefix">Initialization</a>
      <li><a href="#ablePrefix">Disabling and Enabling</a>
      <li><a href="#formatPrefix">Formatting</a>
      <li><a href="#sideEffects">Side Effects</a>
      <li><a href="#validPrefix">Validation</a>
      <li><a href="#linkage">Data Linkage</a>
      </ul>
   <li><a href="#buttons">Buttons</a>
      <ul>
      <li><a href="#dialogButtons">Dialog Buttons</a>
      <li><a href="#jsButtons">Active JavaScript</a>
      </ul>
   </ul>
<a name="minAppRef"></a>
<li><a href="#minApp">A Minimal Complete Application</a>
   <ul>
   <li><a href="#getStarted">Getting Started</a>
      <ul>
      <li><a href="#localization">Localization</a>
      <li><a href="#navigation">Navigation</a>
      <li><a href="#choosing">Choosing Objects</a>
      <li><a href="#editing">Editing</a>
      <li><a href="#btnLinks">Buttons vs. Links</a>
      </ul>
   <li><a href="#dataModel">The Data Model</a>
   <li><a href="#usage">Usage</a>
      <ul>
      <li><a href="#cuSu">Customer/Supplier</a>
      <li><a href="#item">Item</a>
      <li><a href="#order">Order</a>
      <li><a href="#reports">Reports</a>
      </ul>
   <li><a href="#bugs">Bugs</a>
   </ul>
</ul>


<p><hr>
<h2><a name="static">Static Pages</a></h2>

<p>You can use PicoLisp to generate static HTML pages. This does not make much
sense in itself, because you could directly write HTML code as well, but it
forms the base for interactive applications, and allows us to introduce the
application server and other fundamental concepts.

<p><hr>
<h3><a name="hello">Hello World</a></h3>

<p>To begin with a minimal application, please enter the following two lines
into a generic source file named "project.l" in the PicoLisp installation
directory.

<pre><code>
########################################################################
(html 0 "Hello" "@lib.css" NIL
   "Hello World!" )
########################################################################
</code></pre>

<p>(We will modify and use this file in all following examples and experiments.
Whenever you find such a program snippet between hash ('#') lines, just copy and
paste it into your "project.l" file, and press the "reload" button of your
browser to view the effects)


<h4><a name="server">Start the application server</a></h4>

<p>Open a second terminal window, and start a PicoLisp application server

<pre><code>
$ pil @lib/http.l @lib/xhtml.l @lib/form.l -'server 8080 "project.l"' +
</code></pre>

<p>No prompt appears. The server just sits, and waits for connections. You can
stop it later by hitting <code>Ctrl-C</code> in that terminal, or by executing
'<code>killall pil</code>' in some other window.

<p>(In the following, we assume that this HTTP server is up and running)

<p>Now open the URL '<code><a
href="http://localhost:8080">http://localhost:8080</a></code>' with your
browser. You should see an empty page with a single line of text.


<h4><a name="how">How does it work?</a></h4>

<p>The above line loads the debugger (via the '+' switch), the HTTP server code
("@lib/http.l"), the XHTML functions ("@lib/xhtml.l") and the input form
framework ("@lib/form.l", it will be needed later for <a
href="#forms">interactive forms</a>).

<p>Then the <code>server</code> function is called with a port number and a
default URL. It will listen on that port for incoming HTTP requests in an
endless loop. Whenever a GET request arrives on port 8080, the file "project.l"
will be <code><a href="refL.html#load">(load)</a></code>ed, causing the
evaluation (= execution) of all its Lisp expressions.

<p>During that execution, all data written to the current output channel is sent
directly to to the browser. The code in "project.l" is responsible to produce
HTML (or anything else the browser can understand).


<p><hr>
<h3><a name="urlSyntax">URL Syntax</a></h3>

<p>The PicoLisp application server uses a slightly specialized syntax when
communicating URLs to and from a client. The "path" part of an URL - which
remains when

<p><ul>
<li>the preceding protocol, host and port specifications,
<li>and the trailing question mark plus arguments
</ul>

are stripped off - is interpreted according so some rules. The most prominent
ones are:

<p><ul>
<li>If a path starts with an exclamation-mark ('!'), the rest (without the '!')
is taken as the name of a Lisp function to be called. All arguments following
the question mark are passed to that function.

<li>If a path ends with ".l" (a dot and a lower case 'L'), it is taken as a Lisp
source file name to be <code><a href="refL.html#load">(load)</a></code>ed. This
is the most common case, and we use it in our example "project.l".

<li>If the extension of a file name matches an entry in the global mime type
table <code>*Mimes</code>, the file is sent to the client with mime-type and
max-age values taken from that table.

<li>Otherwise, the file is sent to the client with a mime-type of
"application/octet-stream" and a max-age of 1 second.

</ul>

<p>An application is free to extend or modify the <code>*Mimes</code> table with
the <code>mime</code> function. For example

<pre><code>
(mime "doc" "application/msword" 60)
</code></pre>

<p>defines a new mime type with a max-age of one minute.

<p>Argument values in URLs, following the path and the question mark, are
encoded in such a way that Lisp data types are preserved:

<p><ul>
<li>An internal symbol starts with a dollar sign ('$')
<li>A number starts with a plus sign ('+')
<li>An external (database) symbol starts with dash ('-')
<li>A list (one level only) is encoded with underscores ('_')
<li>Otherwise, it is a transient symbol (a plain string)

</ul>

<p>In that way, high-level data types can be directly passed to functions
encoded in the URL, or assigned to global variables before a file is loaded.


<p><hr>
<h3><a name="security">Security</a></h3>

<p>It is, of course, a huge security hole that - directly from the URL - any
Lisp source file can be loaded, and any Lisp function can be called. For that
reason, applications must take care to declare exactly which files and functions
are to be allowed in URLs. The server checks a global variable <code><a
href="refA.html#*Allow">*Allow</a></code>, and - when its value is
non-<code>NIL</code> - denies access to anything that does not match its
contents.

<p>Normally, <code>*Allow</code> is not manipulated directly, but set with the
<code><a href="refA.html#allowed">allowed</a></code> and <code><a
href="refA.html#allow">allow</a></code> functions

<pre><code>
(allowed ("app/")
   "!start" "@lib.css" "customer.l" "article.l" )
</code></pre>

<p>This is usually called in the beginning of an application, and allows access
to the directory "@img/", to the function 'start', and to the files "@lib.css",
"customer.l" and "article.l".

<p>Later in the program, <code>*Allow</code> may be dynamically extended with
<code>allow</code>

<pre><code>
(allow "!foo")
(allow "newdir/" T)
</code></pre>

<p>This adds the function 'foo', and the directory "newdir/", to the set of
allowed items.


<h4><a name="pw">The ".pw" File</a></h4>

<p>For a variety of security checks (most notably for using the <code>psh</code>
function, as in some later examples) it is necessary to create a file named
".pw" in the PicoLisp installation directory. This file should contain a single
line of arbitrary data, to be used as a password for identifying local
resources.

<p>The recommeded way to create this file is to call the <code>pw</code>
function, defined in "@lib/http.l"

<pre><code>
$ pil @lib/http.l -'pw 12' -bye
</code></pre>

<p>Please execute this command.


<p><hr>
<h3><a name="htmlFoo">The <code>html</code> Function</a></h3>

<p>Now back to our "Hello World" example. In principle, you could write
"project.l" as a sequence of print statements

<pre><code>
########################################################################
(prinl "HTTP/1.0 200 OK^M")
(prinl "Content-Type: text/html; charset=utf-8")
(prinl "^M")
(prinl "&lt;html&gt;")
(prinl "Hello World!")
(prinl "&lt;/html&gt;")
########################################################################
</code></pre>

<p>but using the <code>html</code> function is much more convenient.

<p>Moreover, <code>html</code> <b>is</b> nothing more than a printing function.
You can see this easily if you connect a PicoLisp Shell (<code>psh</code>) to
the server process (you must have generated a <a href="#pw">".pw" file</a> for
this), and enter the <code>html</code> statement

<pre><code>
$ /usr/lib/picolisp/bin/psh 8080
: (html 0 "Hello" "@lib.css" NIL "Hello World!")
HTTP/1.0 200 OK
Server: PicoLisp
Date: Fri, 29 Dec 2006 07:28:58 GMT
Cache-Control: max-age=0
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;title&gt;Hello&lt;/title&gt;
&lt;base href="http://localhost:8080/"/&gt;
&lt;link rel="stylesheet" type="text/css" href="http://localhost:8080/@lib.css"/&gt;
&lt;/head&gt;
&lt;body&gt;Hello World!&lt;/body&gt;
&lt;/html&gt;
-&gt; &lt;/html&gt;
:  # (type Ctrl-D here to terminate PicoLisp)
</code></pre>

<p>These are the arguments to <code>html</code>:

<ol>

<li><code>0</code>: A max-age value for cache-control (in seconds, zero means
"no-cache"). You might pass a higher value for pages that change seldom, or
<code>NIL</code> for no cache-control at all.

<li><code>"Hello"</code>: The page title.

<li><code>"@lib.css"</code>: A CSS-File name. Pass <code>NIL</code> if you do
not want to use any CSS-File, or a list of file names if you want to give more
than one CSS-File.

<li><code>NIL</code>: A CSS style attribute specification (see the description
of <a href="#cssAttr">CSS Attributes</a> below). It will be passed to the
<code>body</code> tag.

</ol>

<p>After these four arguments, an arbitrary number of expressions may follow.
They form the body of the resulting page, and are evaluated according to a
special rule. <a name="tagRule">This rule</a> is slightly different from the
evaluation of normal Lisp expressions:

<p><ul>

<li>If an argument is an atom (a number or a symbol (string)), its value is
printed immediately.

<li>Otherwise (a list), it is evaluated as a Lisp function (typically some form
of print statement).

</ul>

<p>Therefore, our source file might as well be written as:

<pre><code>
########################################################################
(html 0 "Hello" "@lib.css" NIL
   (prinl "Hello World!") )
########################################################################
</code></pre>

<p>The most typical print statements will be some HTML-tags:

<pre><code>
########################################################################
(html 0 "Hello" "@lib.css" NIL
   (&lt;h1&gt; NIL "Hello World!")
   (&lt;br&gt; "This is some text.")
   (ht:Prin "And this is a number: " (+ 1 2 3)) )
########################################################################
</code></pre>

<p><code>&lt;h1&gt;</code> and <code>&lt;br&gt;</code> are tag functions.
<code>&lt;h1&gt;</code> takes a CSS attribute as its first argument.

<p>Note the use of <code>ht:Prin</code> instead of <code>prin</code>.
<code>ht:Prin</code> should be used for all direct printing in HTML pages,
because it takes care to escape special characters.


<p><hr>
<h3><a name="cssAttr">CSS Attributes</a></h3>

<p>The <a href="#htmlFoo"><code>html</code> function</a> above, and many of the
HTML <a href="#tags">tag functions</a>, accept a CSS attribute specification.
This may be either an atom, a cons pair, or a list of cons pairs. We demonstrate
the effects with the <code>&lt;h1&gt;</code> tag function.

<p>An atom (usually a symbol or a string) is taken as a CSS class name

<pre><code>
: (&lt;h1&gt; 'foo "Title")
&lt;h1 class="foo"&gt;Title&lt;/h1&gt;
</code></pre>

<p>For a cons pair, the CAR is taken as an attribute name, and the CDR as the
attribute's value

<pre><code>
: (&lt;h1&gt; '(id . bar) "Title")
&lt;h1 id="bar"&gt;Title&lt;/h1&gt;
</code></pre>

<p>Consequently, a list of cons pairs gives a set of attribute-value pairs

<pre><code>
: (&lt;h1&gt; '((id . "abc") (lang . "de")) "Title")
&lt;h1 id="abc" lang="de"&gt;Title&lt;/h1&gt;
</code></pre>


<p><hr>
<h3><a name="tags">Tag Functions</a></h3>

<p>All pre-defined XHTML tag functions can be found in "@lib/xhtml.l". We
recommend to look at their sources, and to experiment a bit, by executing them
at a PicoLisp prompt, or by pressing the browser's "Reload" button after editing
the "project.l" file.

<p>For a suitable PicoLisp prompt, either execute (in a separate terminal
window) the PicoLisp Shell (<code>psh</code>) command (works only if the
application server is running, and you did generate a <a href="#pw">".pw"
file</a>)

<pre><code>
$ /usr/lib/picolisp/bin/psh 8080
:
</code></pre>

<p>or start the interpreter stand-alone, with "@lib/xhtml.l" loaded

<pre><code>
$ pil @lib/http.l @lib/xhtml.l +
:
</code></pre>

<p>Note that for all these tag functions the above <a href="#tagRule">tag body
evaluation rule</a> applies.


<h4><a name="simple">Simple Tags</a></h4>

<p>Most tag functions are simple and straightforward. Some of them just print
their arguments

<pre><code>
: (&lt;br&gt; "Hello world")
Hello world&lt;br/&gt;

: (&lt;em&gt; "Hello world")
&lt;em&gt;Hello world&lt;/em&gt;
</code></pre>

<p>while most of them take a <a href="#cssAttr">CSS attribute specification</a>
as their first argument (like the <code>&lt;h1&gt;</code> tag above)

<pre><code>
: (&lt;div&gt; 'main "Hello world")
&lt;div class="main"&gt;Hello world&lt;/div&gt;

: (&lt;p&gt; NIL "Hello world")
&lt;p&gt;Hello world&lt;/p&gt;

: (&lt;p&gt; 'info "Hello world")
&lt;p class="info"&gt;Hello world&lt;/p&gt;
</code></pre>

<p>All of these functions take an arbitrary number of arguments, and may nest to
an arbitrary depth (as long as the resulting HTML is legal)

<pre><code>
: (&lt;div&gt; 'main
   (&lt;h1&gt; NIL "Head")
   (&lt;p&gt; NIL
      (&lt;br&gt; "Line 1")
      "Line"
      (&lt;nbsp&gt;)
      (+ 1 1) ) )
&lt;div class="main"&gt;&lt;h1&gt;Head&lt;/h1&gt;
&lt;p&gt;Line 1&lt;br/&gt;
Line&nbsp;2&lt;/p&gt;
&lt;/div&gt;
</code></pre>


<h4><a name="lists">(Un)ordered Lists</a></h4>

<p>HTML-lists, implemented by the <code>&lt;ol&gt;</code> and
<code>&lt;ul&gt;</code> tags, let you define hierarchical structures. You might
want to paste the following code into your copy of "project.l":

<pre><code>
########################################################################
(html 0 "Unordered List" "@lib.css" NIL
   (&lt;ul&gt; NIL
      (&lt;li&gt; NIL "Item 1")
      (&lt;li&gt; NIL
         "Sublist 1"
         (&lt;ul&gt; NIL
            (&lt;li&gt; NIL "Item 1-1")
            (&lt;li&gt; NIL "Item 1-2") ) )
      (&lt;li&gt; NIL "Item 2")
      (&lt;li&gt; NIL
         "Sublist 2"
         (&lt;ul&gt; NIL
            (&lt;li&gt; NIL "Item 2-1")
            (&lt;li&gt; NIL "Item 2-2") ) )
      (&lt;li&gt; NIL "Item 3") ) )
########################################################################
</code></pre>

<p>Here, too, you can put arbitrary code into each node of that tree, including
other tag functions.


<h4><a name="tables">Tables</a></h4>

<p>Like the hierarchical structures with the list functions, you can generate
two-dimensional tables with the <code>&lt;table&gt;</code> and
<code>&lt;row&gt;</code> functions.

<p>The following example prints a table of numbers and their squares:

<pre><code>
########################################################################
(html 0 "Table" "@lib.css" NIL
   (&lt;table&gt; NIL NIL NIL
      (for N 10                                    # A table with 10 rows
         (&lt;row&gt; NIL N (prin (* N N))) ) ) )     # and 2 columns
########################################################################
</code></pre>

<p>The first argument to <code>&lt;table&gt;</code> is the usual CSS attribute,
the second an optional title ("caption"), and the third an optional list
specifying the column headers. In that list, you may supply a list for a each
column, with a CSS attribute in its CAR, and a tag body in its CDR for the
contents of the column header.

<p>The body of <code>&lt;table&gt;</code> contains calls to the
<code>&lt;row&gt;</code> function. This function is special in that each
expression in its body will go to a separate column of the table. If both for
the column header and the row function an CSS attribute is given, they will be
combined by a space and passed to the HTML <code>&lt;td&gt;</code> tag. This
permits distinct CSS specifications for each column and row.

<p>As an extension of the above table example, let's pass some attributes for
the table itself (not recommended - better define such styles in a CSS file and
then just pass the class name to <code>&lt;table&gt;</code>), right-align both
columns, and print each row in an alternating red and blue color

<pre><code>
########################################################################
(html 0 "Table" "@lib.css" NIL
   (&lt;table&gt;
      '((width . "200px") (style . "border: dotted 1px;"))    # table style
      "Square Numbers"                                        # caption
      '((align "Number") (align "Square"))                    # 2 headers
      (for N 10                                                  # 10 rows
         (&lt;row&gt; (xchg '(red) '(blue))                         # red or blue
            N                                                 # 2 columns
            (prin (* N N) ) ) ) ) )
########################################################################
</code></pre>

<p>If you wish to concatenate two or more cells in a table, so that a single
cell spans several columns, you can pass the symbol '<code>-</code>' for the
additional cell data to <code>&lt;row&gt;</code>. This will cause the data given
to the left of the '<code>-</code>' symbols to expand to the right.

<p>You can also directly specify table structures with the simple
<code>&lt;th&gt;</code>, <code>&lt;tr&gt;</code> and <code>&lt;td&gt;</code> tag
functions.

<p>If you just need a two-dimensional arrangement of components, the even
simpler <code>&lt;grid&gt;</code> function might be convenient:

<pre><code>
########################################################################
(html 0 "Grid" "@lib.css" NIL
   (&lt;grid&gt; 3
      "A" "B" "C"
      123 456 789 ) )
########################################################################
</code></pre>

<p>It just takes a specification for the number of columns (here: 3) as its
first argument, and then a single expression for each cell. Instead of a number,
you can also pass a list of CSS attributes. Then the length of that list will
determine the number of columns. You can change the second line in the above
example to

<pre><code>
   (&lt;grid&gt; '(NIL NIL right)
</code></pre>

<p>Then the third column will be right aligned.


<h4><a name="menus">Menus and Tabs</a></h4>

<p>The two most powerful tag functions are <code>&lt;menu&gt;</code> and
<code>&lt;tab&gt;</code>. Used separately or in combination, they form a
navigation framework with

<p><ul>
<li>menu items which open and close submenus
<li>submenu items which switch to different pages
<li>tabs which switch to different subpages
</ul>

<p>The following example is not very useful, because the URLs of all items link
to the same "project.l" page, but it should suffice to demonstrate the
functionality:

<pre><code>
########################################################################
(html 0 "Menu+Tab" "@lib.css" NIL
   (&lt;div&gt; '(id . menu)
      (&lt;menu&gt;
         ("Item" "project.l")                      # Top level item
         (NIL (&lt;hr&gt;))                              # Plain HTML
         (T "Submenu 1"                            # Submenu
            ("Subitem 1.1" "project.l")
            (T "Submenu 1.2"
               ("Subitem 1.2.1" "project.l")
               ("Subitem 1.2.2" "project.l")
               ("Subitem 1.2.3" "project.l") )
            ("Subitem 1.3" "project.l") )
         (T "Submenu 2"
            ("Subitem 2.1" "project.l")
            ("Subitem 2.2" "project.l") ) ) )
   (&lt;div&gt; '(id . main)
      (&lt;h1&gt; NIL "Menu+Tab")
      (&lt;tab&gt;
         ("Tab1"
            (&lt;h3&gt; NIL "This is Tab 1") )
         ("Tab2"
            (&lt;h3&gt; NIL "This is Tab 2") )
         ("Tab3"
            (&lt;h3&gt; NIL "This is Tab 3") ) ) ) )
########################################################################
</code></pre>

<p><code>&lt;menu&gt;</code> takes a sequence of menu items. Each menu item is a
list, with its CAR either

<p><ul>
<li><code>NIL</code>: The entry is not an active menu item, and the rest of the
list may consist of arbitrary code (usually HTML tags).

<li><code>T</code>: The second element is taken as a submenu name, and a click
on that name will open or close the corresponding submenu. The rest of the list
recursively specifies the submenu items (may nest to arbitrary depth).

<li>Otherwise: The menu item specifies a direct action (instead of opening a
submenu), where the first list element gives the item's name, and the second
element the corresponding URL.

</ul>

<p><code>&lt;tab&gt;</code> takes a list of subpages. Each page is simply a tab
name, followed by arbitrary code (typically HTML tags).

<p>Note that only a single menu and a single tab may be active at the same time.


<p><hr>
<h2><a name="forms">Interactive Forms</a></h2>

<p>In HTML, the only possibility for user input is via <code>&lt;form&gt;</code>
and <code>&lt;input&gt;</code> elements, using the HTTP POST method to
communicate with the server.

<p>"@lib/xhtml.l" defines a function called <code>&lt;post&gt;</code>, and a
collection of input tag functions, which allow direct programming of HTML forms.
We will supply only one simple example:

<pre><code>
########################################################################
(html 0 "Simple Form" "@lib.css" NIL
   (&lt;post&gt; NIL "project.l"
      (&lt;field&gt; 10 '*Text)
      (&lt;submit&gt; "Save") ) )
########################################################################
</code></pre>

<p>This associates a text input field with a global variable <code>*Text</code>.
The field displays the current value of <code>*Text</code>, and pressing the
submit button causes a reload of "project.l" with <code>*Text</code> set to any
string entered by the user.

<p>An application program could then use that variable to do something useful,
for example store its value in a database.

<p>The problem with such a straightforward use of forms is that

<p><ol>
<li>they require the application programmer to take care of maintaining lots of
global variables. Each input field on the page needs an associated variable for
the round trip between server and client.

<li>they do not preserve an application's internal state. Each POST request
spawns an individual process on the server, which sets the global variables to
their new values, generates the HTML page, and terminates thereafter. The
application state has to be passed along explicitly, e.g. using
<code>&lt;hidden&gt;</code> tags.

<li>they are not very interactive. There is typically only a single submit
button. The user fills out a possibly large number of input fields, but changes
will take effect only when the submit button is pressed.

</ol>

<p>Though we wrote a few applications in that style, we recommend the GUI
framework provided by "@lib/form.l". It does not need any variables for the
client/server communication, but implements a class hierarchy of GUI components
for the abstraction of application logic, button actions and data linkage.


<p><hr>
<h3><a name="sessions">Sessions</a></h3>

<p>First of all, we need to establish a persistent environment on the server, to
handle each individual session (for each connected client).

<p>Technically, this is just a child process of the server we started <a
href="#server">above</a>, which does not terminate immediately after it sent its
page to the browser. It is achieved by calling the <code>app</code> function
somewhere in the application's startup code.

<pre><code>
########################################################################
(app)  # Start a session

(html 0 "Simple Session" "@lib.css" NIL
   (&lt;post&gt; NIL "project.l"
      (&lt;field&gt; 10 '*Text)
      (&lt;submit&gt; "Save") ) )
########################################################################
</code></pre>

<p>Nothing else changed from the previous example. However, when you connect
your browser and then look at the terminal window where you started the
application server, you'll notice a colon, the PicoLisp prompt

<pre><code>
$ pil @lib/http.l @lib/xhtml.l @lib/form.l -'server 8080 "project.l"' +
:
</code></pre>

<p>Tools like the Unix <code>ps</code> utility will tell you that now two
<code>picolisp</code> processes are running, the first being the parent of the
second.

<p>If you enter some text, say "abcdef", into the text field in the browser
window, press the submit button, and inspect the Lisp <code>*Text</code>
variable,

<pre><code>
: *Text
-> "abcdef"
</code></pre>

<p>you see that we now have a dedicated PicoLisp process, "connected" to the
client.

<p>You can terminate this process (like any interactive PicoLisp) by hitting
<code>Ctrl-D</code> on an empty line. Otherwise, it will terminate by itself if
no other browser requests arrive within a default timeout period of 5 minutes.

<p>To start a (non-debug) production version, the server is commonly started
without the '+' flag, and with <code>-wait</code>

<pre><code>
$ pil @lib/http.l @lib/xhtml.l @lib/form.l -'server 8080 "project.l"' -wait
</code></pre>

<p>In that way, no command line prompt appears when a client connects.


<p><hr>
<h3><a name="actionForms">Action Forms</a></h3>

<p>Now that we have a persistent session for each client, we can set up an
active GUI framework.

<p>This is done by wrapping the call to the <code>html</code> function with
<code>action</code>. Inside the body of <code>html</code> can be - in addition
to all other kinds of tag functions - one or more calls to <code>form</code>

<pre><code>
########################################################################
(app)                                              # Start session

(action                                            # Action handler
   (html 0 "Form" "@lib.css" NIL                   # HTTP/HTML protocol
      (form NIL                                    # Form
         (gui 'a '(+TextField) 10)                 # Text Field
         (gui '(+Button) "Print"                   # Button
            '(msg (val&gt; (: home a))) ) ) ) )
########################################################################
</code></pre>

<p>Note that there is no longer a global variable like <code>*Text</code> to
hold the contents of the input field. Instead, we gave a local, symbolic name
'<code>a</code>' to a <code>+TextField</code> component

<pre><code>
         (gui 'a '(+TextField) 10)                 # Text Field
</code></pre>

<p>Other components can refer to it

<pre><code>
            '(msg (val&gt; (: home a)))
</code></pre>

<p><code>(: home)</code> is always the form which contains this GUI component.
So <code>(: home a)</code> evaluates to the component '<code>a</code>' in the
current form. As <code><a href="refM.html#msg">msg</a></code> prints its
argument to standard error, and the <code>val&gt;</code> method retrieves the
current contents of a component, we will see on the console the text typed into
the text field when we press the button.

<p>An <code>action</code> without embedded <code>form</code>s - or a
<code>form</code> without a surrounding <code>action</code> - does not make much
sense by itself. Inside <code>html</code> and <code>form</code>, however, calls
to HTML functions (and any other Lisp functions, for that matter) can be freely
mixed.

<p>In general, a typical page may have the form

<pre><code>
(action                                            # Action handler
   (html ..                                        # HTTP/HTML protocol
      (&lt;h1&gt; ..)                                    # HTML tags
      (form NIL                                    # Form
         (&lt;h3&gt; ..)
         (gui ..)                                  # GUI component(s)
         (gui ..)
         .. )
      (&lt;h2&gt; ..)
      (form NIL                                    # Another form
         (&lt;h3&gt; ..)
         (gui ..)                                  # GUI component(s)
         .. )
      (&lt;br&gt; ..)
      .. ) )
</code></pre>


<h4><a name="guiFoo">The <code>gui</code> Function</a></h4>

<p>The most prominent function in a <code>form</code> body is <code>gui</code>.
It is the workhorse of GUI construction.

<p>Outside of a <code>form</code> body, <code>gui</code> is undefined.
Otherwise, it takes an optional alias name, a list of classes, and additional
arguments as needed by the constructors of these classes. We saw this example
before

<pre><code>
         (gui 'a '(+TextField) 10)                 # Text Field
</code></pre>

Here, '<code>a</code>' is an alias name for a component of type
<code>(+TextField)</code>. The numeric argument <code>10</code> is passed to the
text field, specifying its width. See the chapter on <a href="#guiClasses">GUI
Classes</a> for more examples.

<p>During a GET request, <code>gui</code> is basically a front-end to
<code>new</code>. It builds a component, stores it in the internal structures of
the current form, and initializes it by sending the <code>init&gt;</code>
message to the component. Finally, it sends it the <code>show&gt;</code>
message, to produce HTML code and transmit it to the browser.

<p>During a POST request, <code>gui</code> does not build any new components.
Instead, the existing components are re-used. So <code>gui</code> does not have
much more to do than sending the <code>show&gt;</code> message to a component.


<h4><a name="ctlFlow">Control Flow</a></h4>

<p>HTTP has only two methods to change a browser window: GET and POST. We employ
these two methods in a certain defined, specialized way:

<p><ul>
<li>GET means, a <b>new page</b> is being constructed. It is used when a page is
visited for the first time, usually by entering an URL into the browser's
address field, or by clicking on a link (which is often a <a
href="#menus">submenu item or tab</a>).

<li>POST is always directed to the <b>same page</b>. It is triggered by a button
press, updates the corresponding form's data structures, and executes that
button's action code.

</ul>

<p>A button's action code can do almost anything: Read and modify the contents
of input fields, communicate with the database, display alerts and dialogs, or
even fake the POST request to a GET, with the effect of showing a completely
different document (See <a href="#switching">Switching URLs</a>).

<p>GET builds up all GUI components on the server. These components are objects
which encapsulate state and behavior of the HTML page in the browser. Whenever a
button is pressed, the page is reloaded via a POST request. Then - before any
output is sent to the browser - the <code>action</code> function takes control.
It performs error checks on all components, processes possible user input on the
HTML page, and stores the values in correct format (text, number, date, object
etc.) in each component.

<p>The state of a form is preserved over time. When the user returns to a
previous page with the browser's BACK button, that state is reactivated, and may
be POSTed again.

<p>The following silly example displays two text fields. If you enter some text
into the "Source" field, you can copy it in upper or lower case to the
"Destination" field by pressing one of the buttons

<pre><code>
########################################################################
(app)

(action
   (html 0 "Case Conversion" "@lib.css" NIL
      (form NIL
         (&lt;grid&gt; 2
            "Source" (gui 'src '(+TextField) 30)
            "Destination" (gui 'dst '(+Lock +TextField) 30) )
         (gui '(+JS +Button) "Upper Case"
            '(set&gt; (: home dst)
               (uppc (val&gt; (: home src))) ) )
         (gui '(+JS +Button) "Lower Case"
            '(set&gt; (: home dst)
               (lowc (val&gt; (: home src))) ) ) ) ) )
########################################################################
</code></pre>

<p>The <code>+Lock</code> prefix class in the "Destination" field makes that
field read-only. The only way to get some text into that field is by using one
of the buttons.


<h4><a name="switching">Switching URLs</a></h4>

<p>Because an action code runs before <code>html</code> has a chance to output
an HTTP header, it can abort the current page and present something different to
the user. This might, of course, be another HTML page, but would not be very
interesting as a normal link would suffice. Instead, it can cause the download
of dynamically generated data.

<p>The next example shows a text area and two buttons. Any text entered into the
text area is exported either as a text file via the first button, or a PDF
document via the second button

<pre><code>
########################################################################
(load "@lib/ps.l")

(app)

(action
   (html 0 "Export" "@lib.css" NIL
      (form NIL
         (gui '(+TextField) 30 8)
         (gui '(+Button) "Text"
            '(let Txt (tmp "export.txt")
               (out Txt (prinl (val&gt; (: home gui 1))))
               (url Txt) ) )
         (gui '(+Button) "PDF"
            '(psOut NIL "foo"
               (a4)
               (indent 40 40)
               (down 60)
               (hline 3)
               (font (14 . "Times-Roman")
                  (ps (val&gt; (: home gui 1))) )
               (hline 3)
               (page) ) ) ) ) )
########################################################################
</code></pre>

<p>(a text area is built when you supply two numeric arguments (columns and
rows) to a <code>+TextField</code> class)

<p>The action code of the first button creates a temporary file (i.e. a file
named "export.txt" in the current process's temporary space), prints the value
of the text area (this time we did not bother to give it a name, we simply refer
to it as the form's first gui list element) into that file, and then calls the
<code>url</code> function with the file name.

<p>The second button uses the PostScript library "@lib/ps.l" to create a
temporary file "foo.pdf". Here, the temporary file creation and the call to the
<code>url</code> function is hidden in the internal mechanisms of
<code>psOut</code>. The effect is that the browser receives a PDF document and
displays it.


<h4><a name="dialogs">Alerts and Dialogs</a></h4>

<p>Alerts and dialogs are not really what they used to be ;-)

<p>They do not "pop up". In this framework, they are just a kind of
simple-to-use, pre-fabricated form. They can be invoked by a button's action
code, and appear always on the current page, immediately preceding the form
which created them.

<p>Let's look at an example which uses two alerts and a dialog. In the
beginning, it displays a simple form, with a locked text field, and two buttons

<pre><code>
########################################################################
(app)

(action
   (html 0 "Alerts and Dialogs" "@lib.css" NIL
      (form NIL
         (gui '(+Init +Lock +TextField) "Initial Text" 20 "My Text")
         (gui '(+Button) "Alert"
            '(alert NIL "This is an alert " (okButton)) )
         (gui '(+Button) "Dialog"
            '(dialog NIL
               (&lt;br&gt; "This is a dialog.")
               (&lt;br&gt;
                  "You can change the text here "
                  (gui '(+Init +TextField) (val&gt; (: top 1 gui 1)) 20) )
               (&lt;br&gt; "and then re-submit it to the form.")
               (gui '(+Button) "Re-Submit"
                  '(alert NIL "Are you sure? "
                     (yesButton
                        '(set&gt; (: home top 2 gui 1)
                           (val&gt; (: home top 1 gui 1)) ) )
                     (noButton) ) )
               (cancelButton) ) ) ) ) )
########################################################################
</code></pre>

<p>The <code>+Init</code> prefix class initializes the "My Text" field with the
string "Initial Text". As the field is locked, you cannot modify this value
directly.

<p>The first button brings up an alert saying "This is an alert.". You can
dispose it by pressing "OK".

<p>The second button brings up a dialog with an editable text field, containing
a copy of the value from the form's locked text field. You can modify this
value, and send it back to the form, if you press "Re-Submit" and answer "Yes"
to the "Are you sure?" alert.


<h4><a name="calc">A Calculator Example</a></h4>

<p>Now let's forget our "project.l" test file for a moment, and move on to a
more substantial and practical, stand-alone, example. Using what we have learned
so far, we want to build a simple bignum calculator. ("bignum" because PicoLisp
can do <i>only</i> bignums)

<p>It uses a single form, a single numeric input field, and lots of buttons. It
can be found in the PicoLisp distribution (e.g. under "/usr/share/picolisp/") in
"misc/calc.l", together with a directly executable wrapper script "misc/calc".

<p>To use it, change to the PicoLisp installation directory, and start it as

<pre><code>
$ misc/calc
</code></pre>

<p>or call it with an absolute path, e.g.

<pre><code>
$ /usr/share/picolisp/misc/calc
</code></pre>

<p>If you like to get a PicoLisp prompt for inspection, start it instead as

<pre><code>
$ pil misc/calc.l -main -go +
</code></pre>

<p>Then - as before - point your browser to '<code><a
href="http://localhost:8080">http://localhost:8080</a></code>'.

<p>The code for the calculator logic and the GUI is rather straightforward. The
entry point is the single function <code>calculator</code>. It is called
directly (as described in <a href="#urlSyntax">URL Syntax</a>) as the server's
default URL, and implicitly in all POST requests. No further file access is
needed once the calculator is running.

<p>Note that for a production application, we inserted an allow-statement (as
recommended by the <a href="#security">Security</a> chapter)

<pre><code>
(allowed NIL "!calculator" "@lib.css")
</code></pre>

<p>at the beginning of "misc/calc.l". This will restrict external access to that
single function.

<p>The calculator uses three global variables, <code>*Init</code>,
<code>*Accu</code> and <code>*Stack</code>. <code>*Init</code> is a boolean flag
set by the operator buttons to indicate that the next digit should initialize
the accumulator to zero. <code>*Accu</code> is the accumulator. It is always
displayed in the numeric input field, accepts user input, and it holds the
results of calculations. <code>*Stack</code> is a push-down stack, holding
postponed calculations (operators, priorities and intermediate results) with
lower-priority operators, while calculations with higher-priority operators are
performed.

<p>The function <code>digit</code> is called by the digit buttons, and adds
another digit to the accumulator.

<p>The function <code>calc</code> does an actual calculation step. It pops the
stack, checks for division by zero, and displays an error alert if necessary.

<p><code>operand</code> processes an operand button, accepting a function and a
priority as arguments. It compares the priority with that in the top-of-stack
element, and delays the calculation if it is less.

<p><code>finish</code> is used to calculate the final result.

<p>The <code>calculator</code> function has one numeric input field, with a
width of 60 characters

<pre><code>
         (gui '(+Var +NumField) '*Accu 60)
</code></pre>

<p>The <code>+Var</code> prefix class associates this field with the global
variable <code>*Accu</code>. All changes to the field will show up in that
variable, and modification of that variable's value will appear in the field.

<p>The <a name="sqrtButton">square root operator button</a> has an
<code>+Able</code> prefix class

<pre><code>
         (gui '(+Able +JS +Button) '(ge0 *Accu) (char 8730)
            '(setq *Accu (sqrt *Accu)) )
</code></pre>


<p>with an argument expression which checks that the current value in the
accumulator is positive, and disables the button if otherwise.

<p>The rest of the form is just an array (grid) of buttons, encapsulating all
functionality of the calculator. The user can enter numbers into the input
field, either by using the digit buttons, or by directly typing them in, and
perform calculations with the operator buttons. Supported operations are
addition, subtraction, multiplication, division, sign inversion, square root and
power (all in bignum integer arithmetic). The '<code>C</code>' button just
clears the accumulator, while the '<code>A</code>' button also clears all
pending calculations.

<p>All that in 53 lines of code!


<p><hr>
<h3><a name="charts">Charts</a></h3>

<p>Charts are virtual components, maintaining the internal representation of
two-dimensional data.

<p>Typically, these data are nested lists, database selections, or some kind of
dynamically generated tabular information. Charts make it possible to view them
in rows and columns (usually in HTML <a href="#tables">tables</a>), scroll up
and down, and associate them with their corresponding visible GUI components.

<p>In fact, the logic to handle charts makes up a substantial part of the whole
framework, with large impact on all internal mechanisms. Each GUI component must
know whether it is part of a chart or not, to be able to handle its contents
properly during updates and user interactions.

<p>Let's assume we want to collect textual and numerical data. We might create a
table

<pre><code>
########################################################################
(app)

(action
   (html 0 "Table" "@lib.css" NIL
      (form NIL
         (&lt;table&gt; NIL NIL '((NIL "Text") (NIL "Number"))
            (do 4
               (&lt;row&gt; NIL
                  (gui '(+TextField) 20)
                  (gui '(+NumField) 10) ) ) )
         (&lt;submit&gt; "Save") ) ) )
########################################################################
</code></pre>

<p>with two columns "Text" and "Number", and four rows, each containing a
<code>+TextField</code> and a <code>+NumField</code>.

<p>You can enter text into the first column, and numbers into the second.
Pressing the "Save" button stores these values in the components on the server
(or produces an error message if a string in the second column is not a legal
number).

<p>There are two problems with this solution:

<p><ol>
<li>Though you can get at the user input for the individual fields, e.g.

<pre><code>
: (val> (get *Top 'gui 2))  # Value in the first row, second column
-> 123
</code></pre>

there is no direct way to get the whole data structure as a single list.
Instead, you have to traverse all GUI components and collect the data.

<li>The user cannot input more than four rows of data, because there is no easy
way to scroll down and make space for more.

</ol>

<p>A chart can handle these things:

<pre><code>
########################################################################
(app)

(action
   (html 0 "Chart" "@lib.css" NIL
      (form NIL
         (gui '(+Chart) 2)                         # Inserted a +Chart
         (&lt;table&gt; NIL NIL '((NIL "Text") (NIL "Number"))
            (do 4
               (&lt;row&gt; NIL
                  (gui 1 '(+TextField) 20)         # Inserted '1'
                  (gui 2 '(+NumField) 10) ) ) )    # Inserted '2'
         (&lt;submit&gt; "Save") ) ) )
########################################################################
</code></pre>

<p>Note that we inserted a <code>+Chart</code> component before the GUI
components which should be managed by the chart. The argument '2' tells the
chart that it has to expect two columns.

<p>Each component got an index number (here '1' and '2') as the first argument
to <code>gui</code>, indicating the column into which this component should go
within the chart.

<p>Now - if you entered "a", "b" and "c" into the first, and 1, 2, and 3 into
the second column - we can retrieve the chart's complete contents by sending it
the <code>val&gt;</code> message

<pre><code>
: (val> (get *Top 'chart 1))  # Retrieve the value of the first chart
-> (("a" 1) ("b" 2) ("c" 3))
</code></pre>

<p>BTW, a more convenient function is <code>chart</code>

<pre><code>
: (val> (chart))  # Retrieve the value of the current chart
-> (("a" 1) ("b" 2) ("c" 3))
</code></pre>

<p><code>chart</code> can be used instead of the above construct when we want to
access the "current" chart, i.e. the chart most recently processed in the
current form.


<h4><a name="scrolling">Scrolling</a></h4>

<p>To enable scrolling, let's also insert two buttons. We use the pre-defined
classes <code>+UpButton</code> and <code>+DnButton</code>

<pre><code>
########################################################################
(app)

(action
   (html 0 "Scrollable Chart" "@lib.css" NIL
      (form NIL
         (gui '(+Chart) 2)
         (&lt;table&gt; NIL NIL '((NIL "Text") (NIL "Number"))
            (do 4
               (&lt;row&gt; NIL
                  (gui 1 '(+TextField) 20)
                  (gui 2 '(+NumField) 10) ) ) )
         (gui '(+UpButton) 1)                   # Inserted two buttons
         (gui '(+DnButton) 1)
         (----)
         (&lt;submit&gt; "Save") ) ) )
########################################################################
</code></pre>

<p>to scroll down and up a single (argument '1') line at a time.

<p>Now it is possible to enter a few rows of data, scroll down, and continue. It
is not necessary (except in the beginning, when the scroll buttons are still
disabled) to press the "Save" button, because <b>any</b> button in the form will
send changes to the server's internal structures before any action is performed.


<h4><a name="putGet">Put and Get Functions</a></h4>

<p>As we said, a chart is a virtual component to edit two-dimensional data.
Therefore, a chart's native data format is a list of lists: Each sublist
represents a single row of data, and each element of a row corresponds to a
single GUI component.

<p>In the example above, we saw a row like

<pre><code>
   ("a" 1)
</code></pre>

<p>being mapped to

<pre><code>
   (gui 1 '(+TextField) 20)
   (gui 2 '(+NumField) 10)
</code></pre>

<p>Quite often, however, such a one-to-one relationship is not desired. The
internal data structures may have to be presented in a different form to the
user, and user input may need conversion to an internal representation.

<p>For that, a chart accepts - in addition to the "number of columns" argument -
two optional function arguments. The first function is invoked to 'put' the
internal representation into the GUI components, and the second to 'get' data
from the GUI into the internal representation.

<p>A typical example is a chart displaying customers in a database. While the
internal representation is a (one-dimensional) list of customer objects, 'put'
expands each object to a list with, say, the customer's first and second name,
telephone number, address and so on. When the user enters a customer's name,
'get' locates the matching object in the database and stores it in the internal
representation. In the following, 'put' will in turn expand it to the GUI.

<p>For now, let's stick with a simpler example: A chart that holds just a list
of numbers, but expands in the GUI to show also a textual form of each number
(in German).

<pre><code>
########################################################################
(app)

(load "@lib/zahlwort.l")

(action
   (html 0 "Numerals" "@lib.css" NIL
      (form NIL
         (gui '(+Init +Chart) (1 5 7) 2
            '((N) (list N (zahlwort N)))
            car )
         (&lt;table&gt; NIL NIL '((NIL "Numeral") (NIL "German"))
            (do 4
               (&lt;row&gt; NIL
                  (gui 1 '(+NumField) 9)
                  (gui 2 '(+Lock +TextField) 90) ) ) )
         (gui '(+UpButton) 1)
         (gui '(+DnButton) 1)
         (----)
         (&lt;submit&gt; "Save") ) ) )
########################################################################
</code></pre>

<p>"@lib/zahlwort.l" defines the utility function <code>zahlwort</code>, which
is required later by the 'put' function. <code>zahlwort</code> accepts a number
and returns its wording in German.

<p>Now look at the code

<pre><code>
         (gui '(+Init +Chart) (1 5 7) 2
            '((N) (list N (zahlwort N)))
            car )
</code></pre>

<p>We prefix the <code>+Chart</code> class with <code>+Init</code>, and pass it
a list of numbers <code>(1 5 7)</code> for the initial value of the chart. Then,
following the '2' (the chart has two columns), we pass a 'put' function

<pre><code>
            '((N) (list N (zahlwort N)))
</code></pre>

<p>which takes a number and returns a list of that number and its wording, and a
'get' function

<pre><code>
            car )
</code></pre>

<p>which in turn accepts such a list and returns a number, which happens to be
the list's first element.

<p>You can see from this example that 'get' is the inverse function of 'put'.
'get' can be omitted, however, if the chart is read-only (contains no (or only
locked) input fields).

<p>The field in the second column

<pre><code>
                  (gui 2 '(+Lock +TextField) 90) ) ) )
</code></pre>

<p>is locked, because it displays the text generated by 'put', and is not
supposed to accept any user input.

<p>When you start up this form in your browser, you'll see three pre-filled
lines with "1/eins", "5/fünf" and "7/sieben", according to the
<code>+Init</code> argument <code>(1 5 7)</code>. Typing a number somewhere into
the first column, and pressing ENTER or one of the buttons, will show a suitable
text in the second column.


<p><hr>
<h2><a name="guiClasses">GUI Classes</a></h2>

<p>In previous chapters we saw examples of GUI classes like
<code>+TextField</code>, <code>+NumField</code> or <code>+Button</code>, often
in combination with prefix classes like <code>+Lock</code>, <code>+Init</code>
or <code>+Able</code>. Now we take a broader look at the whole hierarchy, and
try more examples.

<p>The abstract class <code>+gui</code> is the base of all GUI classes. A live
view of the class hierarchy can be obtained with the <code><a
href="refD.html#dep">dep</a></code> ("dependencies") function:

<pre><code>
: (dep '+gui)
+gui
   +JsField
   +Button
      +UpButton
      +PickButton
         +DstButton
      +ClrButton
      +ChoButton
         +Choice
      +GoButton
      +BubbleButton
      +DelRowButton
      +ShowButton
      +DnButton
   +Img
   +field
      +Checkbox
      +TextField
         +FileField
         +ClassField
         +numField
            +NumField
            +FixField
         +BlobField
         +DateField
         +SymField
         +UpField
         +MailField
         +SexField
         +AtomField
         +PwField
         +ListTextField
         +LinesField
         +TelField
         +TimeField
         +HttpField
      +Radio
-> +gui
</code></pre>

<p>We see, for example, that <code>+DnButton</code> is a subclass of
<code>+Button</code>, which in turn is a subclass of <code>+gui</code>.
Inspecting <code>+DnButton</code> directly

<pre><code>
: (dep '+DnButton)
   +Tiny
   +Rid
   +JS
   +Able
      +gui
   +Button
+DnButton
-> +DnButton
</code></pre>

<p>shows that <code>+DnButton</code> inherits from <code>+Tiny</code>,
<code>+Rid</code>, <code>+Able</code> and <code>+Button</code>. The actual
definition of <code>+DnButton</code> can be found in "@lib/form.l"

<pre><code>
(class +DnButton +Tiny +Rid +JS +Able +Button)
...
</code></pre>

<p>In general, "@lib/form.l" is the ultimate reference to the framework, and
should be freely consulted.


<p><hr>
<h3><a name="inputFields">Input Fields</a></h3>

<p>Input fields implement the visual display of application data, and allow -
when enabled - input and modification of these data.

<p>On the HTML level, they can take the form of

<ul>
<li>Normal text input fields
<li>Textareas
<li>Checkboxes
<li>Drop-down selections
<li>Password fields
<li>HTML links
<li>Plain HTML text
</ul>

<p>Except for checkboxes, which are implemented by the <a
href="#checkboxes">Checkbox</a> class, all these HTML representations are
generated by <code>+TextField</code> and its content-specific subclasses like
<code>+NumField</code>, <code>+DateField</code> etc. Their actual appearance (as
one of the above forms) depends on their arguments:

<p>We saw already "normal" text fields. They are created with a single numeric
argument. This example creates an editable field with a width of 10 characters:

<pre><code>
   (gui '(+TextField) 10)
</code></pre>

<p>If you supply a second numeric for the line count ('4' in this case), you'll
get a text area:

<pre><code>
   (gui '(+TextField) 10 4)
</code></pre>

<p>Supplying a list of values instead of a count yields a drop-down selection
(combo box):

<pre><code>
   (gui '(+TextField) '("Value 1" "Value 2" "Value 3"))
</code></pre>

<p>In addition to these arguments, you can pass a string. Then the field is
created with a label:

<pre><code>
   (gui '(+TextField) 10 "Plain")
   (gui '(+TextField) 10 4 "Text Area")
   (gui '(+TextField) '("Value 1" "Value 2" "Value 3") "Selection")
</code></pre>

<p>Finally, without any arguments, the field will appear as a plain HTML text:

<pre><code>
   (gui '(+TextField))
</code></pre>

<p>This makes mainly sense in combination with prefix classes like
<code>+Var</code> and <code>+Obj</code>, to manage the contents of these fields,
and achieve special behavior as HTML links or scrollable chart values.


<h4><a name="numberFields">Numeric Input Fields</a></h4>

<p>A <code>+NumField</code> returns a number from its <code>val&gt;</code>
method, and accepts a number for its <code>set&gt;</code> method. It issues an
error message when user input cannot be converted to a number.

<p>Large numbers are shown with a thousands-separator, as determined by the
current locale.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+NumField" "@lib.css" NIL
      (form NIL
         (gui '(+NumField) 10)
         (gui '(+JS +Button) "Print value"
            '(msg (val&gt; (: home gui 1))) )
         (gui '(+JS +Button) "Set to 123"
            '(set&gt; (: home gui 1) 123) ) ) ) )
########################################################################
</code></pre>

<p>A <code>+FixField</code> needs an additional scale factor argument, and
accepts/returns scaled fixpoint numbers.

<p>The decimal separator is determined by the current locale.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+FixField" "@lib.css" NIL
      (form NIL
         (gui '(+FixField) 3 10)
         (gui '(+JS +Button) "Print value"
            '(msg (format (val&gt; (: home gui 1)) 3)) )
         (gui '(+JS +Button) "Set to 123.456"
            '(set&gt; (: home gui 1) 123456) ) ) ) )
########################################################################
</code></pre>


<h4><a name="timeDateFields">Time &amp; Date</a></h4>

<p>A <code>+DateField</code> accepts and returns a <code><a
href="refD.html#date">date</a></code> value.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+DateField" "@lib.css" NIL
      (form NIL
         (gui '(+DateField) 10)
         (gui '(+JS +Button) "Print value"
            '(msg (datStr (val&gt; (: home gui 1)))) )
         (gui '(+JS +Button) "Set to \"today\""
            '(set&gt; (: home gui 1) (date)) ) ) ) )
########################################################################
</code></pre>

<p>The format displayed to - and entered by - the user depends on the current
locale (see <code><a href="refD.html#datStr">datStr</a></code> and <code><a
href="refE.html#expDat">expDat</a></code>). You can change it, for example to

<pre><code>
: (locale "DE" "de")
-> NIL
</code></pre>

<p>If no locale is set, the format is YYYY-MM-DD. Some pre-defined locales use
patterns like DD.MM.YYYY (DE), YYYY/MM/DD (JP), DD/MM/YYYY (UK), or MM/DD/YYYY
(US).

<p>An error is issued when user input does not match the current locale's date
format.

<p>Independent from the locale setting, a <code>+DateField</code> tries to
expand abbreviated input from the user. A small number is taken as that day of
the current month, larger numbers expand to day and month, or to day, month and
year:

<ul>
<li>"7" gives the 7th of the current month
<li>"031" or "0301" give the 3rd of January of the current year
<li>"311" or "3101" give the 31st of January of the current year
<li>"0311" gives the 3rd of November of the current year
<li>"01023" or "010203" give the first of February in the year 2003
<li>and so on
</ul>

<p>Similar is the <code>+TimeField</code>. It accepts and returns a <code><a
href="refT.html#time">time</a></code> value.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+TimeField" "@lib.css" NIL
      (form NIL
         (gui '(+TimeField) 8)
         (gui '(+JS +Button) "Print value"
            '(msg (tim$ (val&gt; (: home gui 1)))) )
         (gui '(+JS +Button) "Set to \"now\""
            '(set&gt; (: home gui 1) (time)) ) ) ) )
########################################################################
</code></pre>

<p>When the field width is '8', like in this example, time is displayed in the
format <code>HH:MM:SS</code>. Another possible value would be '5', causing
<code>+TimeField</code> to display its value as <code>HH:MM</code>.

<p>An error is issued when user input cannot be converted to a time value.

<p>The user may omit the colons. If he inputs just a small number, it should be
between '0' and '23', and will be taken as a full hour. '125' expands to
"12:05", '124517' to "12:45:17", and so on.


<h4><a name="telFields">Telephone Numbers</a></h4>

<p>Telephone numbers are represented internally by the country code (without a
leading plus sign or zero) followed by the local phone number (ideally separated
by spaces) and the phone extension (ideally separated by a hyphen). The exact
format of the phone number string is not enforced by the GUI, but further
processing (e.g. database searches) normally uses <code><a
href="refF.html#fold">fold</a></code> for better reproducibility.

<p>To display a phone number, <code>+TelField</code> replaces the country code
with a single zero if it is the country code of the current locale, or prepends
it with a plus sign if it is a foreign country (see <code><a
href="refT.html#telStr">telStr</a></code>).

<p>For user input, a plus sign or a double zero is simply dropped, while a
single leading zero is replaced with the current locale's country code (see
<code><a href="refE.html#expTel">expTel</a></code>).

<pre><code>
########################################################################
(app)
(locale "DE" "de")

(action
   (html 0 "+TelField" "@lib.css" NIL
      (form NIL
         (gui '(+TelField) 20)
         (gui '(+JS +Button) "Print value"
            '(msg (val&gt; (: home gui 1))) )
         (gui '(+JS +Button) "Set to \"49 1234 5678-0\""
            '(set&gt; (: home gui 1) "49 1234 5678-0") ) ) ) )
########################################################################
</code></pre>


<h4><a name="checkboxes">Checkboxes</a></h4>

<p>A <code>+Checkbox</code> is straightforward. User interaction is restricted
to clicking it on and off. It accepts boolean (<code>NIL</code> or
non-<code>NIL</code>) values, and returns <code>T</code> or <code>NIL</code>.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+Checkbox" "@lib.css" NIL
      (form NIL
         (gui '(+Checkbox))
         (gui '(+JS +Button) "Print value"
            '(msg (val&gt; (: home gui 1))) )
         (gui '(+JS +Button) "On"
            '(set&gt; (: home gui 1) T) )
         (gui '(+JS +Button) "Off"
            '(set&gt; (: home gui 1) NIL) ) ) ) )
########################################################################
</code></pre>


<p><hr>
<h3><a name="fieldPrefix">Field Prefix Classes</a></h3>

<p>A big part of this framework's power is owed to the combinatorial flexibility
of prefix classes for GUI- and DB-objects. They allow to surgically override
individual methods in the inheritance tree, and can be combined in various ways
to achieve any desired behavior.

<p>Technically, there is nothing special about prefix classes. They are just
normal classes. They are called "prefix" because they are intended to be written
<i>before</i> other classes in a class's or object's list of superclasses.

<p>Usually they take their own arguments for their <code>T</code> method from
the list of arguments to the <code>gui</code> function.


<h4><a name="initPrefix">Initialization</a></h4>

<p><code>+Init</code> overrides the <code>init&gt;</code> method for that
component. The <code>init&gt;</code> message is sent to a <code>+gui</code>
component when the page is loaded for the first time (during a GET request).
<code>+Init</code> takes an expression for the initial value of that field.

<pre><code>
   (gui '(+Init +TextField) "This is the initial text" 30)
</code></pre>

<p>Other classes which automatically give a value to a field are
<code>+Var</code> (linking the field to a variable) and <code>+E/R</code>
(linking the field to a database entity/relation).

<p><code>+Cue</code> can be used, for example in "mandatory" fields, to give a
hint to the user about what he is supposed to enter. It will display the
argument value, in angular brackets, if and only if the field's value is
<code>NIL</code>, and the <code>val&gt;</code> method will return
<code>NIL</code> despite the fact that this value is displayed.

<p>Cause an empty field to display "&lt;Please enter some text here&gt;":

<pre><code>
   (gui '(+Cue +TextField) "Please enter some text here" 30)
</code></pre>


<h4><a name="ablePrefix">Disabling and Enabling</a></h4>

<p>An important feature of an interactive GUI is the context-sensitive disabling
and enabling of individual components, or of a whole form.

<p>The <code>+Able</code> prefix class takes an argument expression, and
disables the component if this expression returns <code>NIL</code>. We saw an
example for its usage already in the <a href="#sqrtButton">square root
button</a> of the calculator example. Or, for illustration purposes, imagine a
button which is supposed to be enabled only after Christmas

<pre><code>
   (gui '(+Able +Button)
      '(>= (cdr (date (date))) (12 24))
      "Close this year"
      '(endOfYearProcessing) )
</code></pre>

<p>or a password field that is disabled as long as somebody is logged in

<pre><code>
   (gui '(+Able +PwField) '(not *Login) 10 "Password")
</code></pre>

<p>A special case is the <code>+Lock</code> prefix, which permanently and
unconditionally disables a component. It takes no arguments

<pre><code>
   (gui '(+Lock +NumField) 10 "Count")
</code></pre>

<p>('10' and "Count" are for the <code>+NumField</code>), and creates a
read-only field.

<p>The whole form can be disabled by calling <code>disable</code> with a
non-<code>NIL</code> argument. This affects all components in this form. Staying
with the above example, we can make the form read-only until Christmas

<pre><code>
   (form NIL
      (disable (> (12 24) (cdr (date (date)))))  # Disable whole form
      (gui ..)
      .. )
</code></pre>

<p>Even in a completely disabled form, however, it is often necessary to
re-enable certain components, as they are needed for navigation, scrolling, or
other activities which don't affect the contents of the form. This is done by
prefixing these fields with <code>+Rid</code> (i.e. getting "rid" of the lock).

<pre><code>
   (form NIL
      (disable (> (12 24) (cdr (date (date)))))
      (gui ..)
      ..
      (gui '(+Rid +Button) ..)  # Button is enabled despite the disabled form
      .. )
</code></pre>


<h4><a name="formatPrefix">Formatting</a></h4>

<p>GUI prefix classes allow a fine-grained control of how values are stored in -
and retrieved from - components. As in predefined classes like
<code>+NumField</code> or <code>+DateField</code>, they override the
<code>set&gt;</code> and/or <code>val&gt;</code> methods.

<p><code>+Set</code> takes an argument function which is called whenever that
field is set to some value. To convert all user input to upper case

<pre><code>
   (gui '(+Set +TextField) uppc 30)
</code></pre>

<p><code>+Val</code> is the complement to <code>+Set</code>. It takes a function
which is called whenever the field's value is retrieved. To return the square of
a field's value

<pre><code>
   (gui '(+Val +NumField) '((N) (* N N)) 10)
</code></pre>

<p><code>+Fmt</code> is just a combination of <code>+Set</code> and
<code>+Val</code>, and takes two functional arguments. This example will display
upper case characters, while returning lower case characters internally

<pre><code>
   (gui '(+Fmt +TextField) uppc lowc 30)
</code></pre>

<p><code>+Map</code> does (like <code>+Fmt</code>) a two-way translation. It
uses a list of cons pairs for a linear lookup, where the CARs represent the
displayed values which are internally mapped to the values in the CDRs. If a
value is not found in this list during <code>set&gt;</code> or
<code>val&gt;</code>, it is passed through unchanged.

<p>Normally, <code>+Map</code> is used in combination with the combo box
incarnation of text fields (see <a href="#inputFields">Input Fields</a>). This
example displays "One", "Two" and "Three" to the user, but returns a number 1, 2
or 3 internally

<pre><code>
########################################################################
(app)

(action
   (html 0 "+Map" "@lib.css" NIL
      (form NIL
         (gui '(+Map +TextField)
            '(("One" . 1) ("Two" . 2) ("Three" . 3))
            '("One" "Two" "Three") )
         (gui '(+Button) "Print"
            '(msg (val> (field -1))) ) ) ) )
########################################################################
</code></pre>


<h4><a name="sideEffects">Side Effects</a></h4>

<p>Whenever a button is pressed in the GUI, any changes caused by
<code>action</code> in the current environment (e.g. the database or application
state) need to be reflected in the corresponding GUI fields. For that, the
<code>upd&gt;</code> message is sent to all components. Each component then
takes appropriate measures (e.g. refresh from database objects, load values from
variables, or calculate a new value) to update its value.

<p>While the <code>upd&gt;</code> method is mainly used internally, it can be
overridden in existing classes via the <code>+Upd</code> prefix class. Let's
print updated values to standard error

<pre><code>
########################################################################
(app)
(default *Number 0)

(action
   (html 0 "+Upd" "@lib.css" NIL
      (form NIL
         (gui '(+Upd +Var +NumField)
            '(prog (extra) (msg *Number))
            '*Number 8 )
         (gui '(+JS +Button) "Increment"
            '(inc '*Number) ) ) ) )
########################################################################
</code></pre>


<h4><a name="validPrefix">Validation</a></h4>

<p>To allow automatic validation of user input, the <code>chk&gt;</code> message
is sent to all components at appropriate times. The corresponding method should
return <code>NIL</code> if the value is all right, or a string describing the
error otherwise.

<p>Many of the built-in classes have a <code>chk&gt;</code> method. The
<code>+NumField</code> class checks for legal numeric input, or the
<code>+DateField</code> for a valid calendar date.

<p>An on-the-fly check can be implemented with the <code>+Chk</code> prefix
class. The following code only accepts numbers not bigger than 9: The
<code>or</code> expression first delegates the check to the main
<code>+NumField</code> class, and - if it does not give an error - returns an
error string when the current value is greater than 9.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+Chk" "@lib.css" NIL
      (form NIL
         (gui '(+Chk +NumField)
            '(or
               (extra)
               (and (&gt; (val&gt; This) 9) "Number too big") )
            12 )
         (gui '(+JS +Button) "Print"
            '(msg (val&gt; (field -1))) ) ) ) )
########################################################################
</code></pre>

<p>A more direct kind of validation is built-in via the <code>+Limit</code>
class. It controls the <code>maxlength</code> attribute of the generated HTML
input field component. Thus, it is impossible to type to more characters than
allowed into the field.

<pre><code>
########################################################################
(app)

(action
   (html 0 "+Limit" "@lib.css" NIL
      (form NIL
         (gui '(+Limit +TextField) 4 8)
         (gui '(+JS +Button) "Print"
            '(msg (val&gt; (field -1))) ) ) ) )
########################################################################
</code></pre>


<h4><a name="linkage">Data Linkage</a></h4>

<p>Although <code>set&gt;</code> and <code>val&gt;</code> are the official
methods to get a value in and out of a GUI component, they are not very often
used explicitly. Instead, components are directly linked to internal Lisp data
structures, which are usually either variables or database objects.

<p>The <code>+Var</code> prefix class takes a variable (described as the
<code>var</code> data type - either a symbol or a cons pair - in the <a
href="ref.html#fun">Function Reference</a>). In the following example, we
initialize a global variable with the value "abc", and let a
<code>+TextField</code> operate on it. The "Print" button can be used to display
its current value.

<pre><code>
########################################################################
(app)

(setq *TextVariable "abc")

(action
   (html 0 "+Var" "@lib.css" NIL
      (form NIL
         (gui '(+Var +TextField) '*TextVariable 8)
         (gui '(+JS +Button) "Print"
            '(msg *TextVariable) ) ) ) )
########################################################################
</code></pre>

<p><code>+E/R</code> takes an entity/relation specification. This is a cons
pair, with a relation in its CAR (e.g. <code>nm</code>, for an object's name),
and an expression in its CDR (typically <code>(: home obj)</code>, the object
stored in the <code>obj</code> property of the current form).

<p>For an isolated, simple example, we create a temporary database, and access
the <code>nr</code> and <code>nm</code> properties of an object stored in a
global variable <code>*Obj</code>.

<pre><code>
########################################################################
(when (app)                # On start of session
   (class +Tst +Entity)    # Define data model
   (rel nr (+Number))      # with a number
   (rel nm (+String))      # and a string
   (pool (tmp "db"))       # Create temporary DB
   (setq *Obj              # and a single object
      (new! '(+Tst) 'nr 1 'nm "New Object") ) )

(action
   (html 0 "+E/R" "@lib.css" NIL
      (form NIL
         (gui '(+E/R +NumField) '(nr . *Obj) 8)    # Linkage to 'nr'
         (gui '(+E/R +TextField) '(nm . *Obj) 20)  # Linkage to 'nm'
         (gui '(+JS +Button) "Show"                # Show the object
            '(out 2 (show *Obj)) ) ) ) )           # on standard error
########################################################################
</code></pre>


<p><hr>
<h3><a name="buttons">Buttons</a></h3>

<p>Buttons are, as explained in <a href="#ctlFlow">Control Flow</a>, the only
way (via POST requests) for an application to communicate with the server.

<p>Basically, a <code>+Button</code> takes

<ul>
<li>a label, which may be either a string or the name of an image file
<li>an optional alternative label, shown when the button is disabled
<li>and an executable expression.
</ul>

<p>Here is a minimal button, with just a label and an expression:

<pre><code>
   (gui '(+Button) "Label" '(doSomething))
</code></pre>

<p>And this is a button displaying different labels, depending on the state:

<pre><code>
   (gui '(+Button) "Enabled" "Disabled" '(doSomething))
</code></pre>

<p>To show an image instead of plain text, the label(s) must be preceeded by the
<code>T</code> symbol:

<pre><code>
   (gui '(+Button) T "img/enabled.png" "img/disabled.png" '(doSomething))
</code></pre>

<p>The expression will be executed during <code>action</code> handling (see <a
href="#actionForms">Action Forms</a>), when this button was pressed.

<p>Like other components, buttons can be extended and combined with prefix
classes, and a variety of predefined classes and class combinations are
available.


<h4><a name="dialogButtons">Dialog Buttons</a></h4>

<p>Buttons are essential for the handling of <a href="#dialogs">alerts and
dialogs</a>. Besides buttons for normal functions, like <a
href="#scrolling">scrolling</a> in charts or other <a href="#sideEffects">side
effects</a>, special buttons exist which can <i>close</i> an alert or dialog in
addition to doing their principal job.

<p>Such buttons are usually subclasses of <code>+Close</code>, and most of them
can be called easily with ready-made functions like <code>closeButton</code>,
<code>cancelButton</code>, <code>yesButton</code> or <code>noButton</code>. We
saw a few examples in <a href="#dialogs">Alerts and Dialogs</a>.


<h4><a name="jsButtons">Active JavaScript</a></h4>

<p>When a button inherits from the <code>+JS</code> class (and JavaScript is
enabled in the browser), that button will possibly show a much faster response
in its action.

<p>The reason is that the activation of a <code>+JS</code> button will - instead
of doing a normal POST - first try to send only the contents of all GUI
components via an XMLHttpRequest to the server, and receive the updated values
in response. This avoids the flicker caused by reloading and rendering of the
whole page, is much faster, and also does not jump to the beginning of the page
if it is larger than the browser window. The effect is especially noticeable
while scrolling in charts.

<p>Only if this fails, for example because an error message was issued, or a
dialog popped up, it will fall back, and the form will be POSTed in the normal
way.

<p>Thus it makes no sense to use the <code>+JS</code> prefix for buttons that
cause a change of the HTML code, open a dialog, or jump to another page. In such
cases, overall performance will even be worse, because the XMLHttpRequest is
tried first (but in vain).

<p>When JavaScript is disabled int the browser, the XMLHttpRequest will not be
tried at all. The form will be fully usable, though, with identical
functionality and behavior, just a bit slower and not so smooth.


<p><hr>
<h2><a name="minApp">A Minimal Complete Application</a></h2>

<p>The PicoLisp release includes in the "app/" directory a minimal, yet complete
reference application. This application is typical, in the sense that it
implements many of the techniques described in this document, and it can be
easily modified and extended. In fact, we use it as templates for our own
production application development.

<p>It is a kind of simplified ERP system, containing customers/suppliers,
products (items), orders, and other data. The order input form performs live
updates of customer and product selections, price, inventory and totals
calculations, and generates on-the-fly PDF documents. Fine-grained access
permissions are controlled via users, roles and permissions. It comes localized
in six languages (English, Spanish, German, Norwegian, Russian and Japanese),
with some initial data and two sample reports.


<p><hr>
<h3><a name="getStarted">Getting Started</a></h3>

<p>For a global installation (see <a href="ref.html#inst">Installation</a>),
please create a symbolic link to the place where the program files are
installed. This is necessary because the application needs read/write access to
the current working directory (for the database and other runtime data).

<pre><code>
$ ln -s /usr/share/picolisp/app
</code></pre>

<p>As ever, you may start up the application in debugging mode

<pre><code>
$ pil app/main.l -main -go +
</code></pre>

<p>or in (non-debug) production mode

<pre><code>
$ pil app/main.l -main -go -wait
</code></pre>

<p>and go to '<code><a
href="http://localhost:8080">http://localhost:8080</a></code>' with your
browser. You can login as user "admin", with password "admin". The demo data
contain several other users, but those are more restricted in their role
permissions.

<p>Another possibility is to try the online version of this application at <a
href="http://app.7fach.de">app.7fach.de</a>.


<h4><a name="localization">Localization</a></h4>

<p>Before or after you logged in, you can select another language, and click on
the "Change" button. This will effect all GUI components (though not text from
the database), and also the numeric, date and telephone number formats.


<h4><a name="navigation">Navigation</a></h4>

<p>The navigation menu on the left side shows two items "Home" and "logout", and
three submenus "Data", "Report" and "System".

<p>Both "Home" and "logout" bring you back to the initial login form. Use
"logout" if you want to switch to another user (say, for another set of
permissions), and - more important - before you close your browser, to release
possible locks and process resources on the server.

<p>The "Data" submenu gives access to application specific data entry and
maintenance: Orders, product items, customers and suppliers. The "Report"
submenu contains two simple inventory and sales reports. And the "System"
submenu leads to role and user administration.

<p>You can open and close each submenu individually. Keeping more than one
submenu open at a time lets you switch rapidly between different parts of the
application.

<p>The currently active menu item is indicated by a highlighted list style (no
matter whether you arrived at this page directly via the menu or by clicking on
a link somewhere else).


<h4><a name="choosing">Choosing Objects</a></h4>

<p>Each item in the "Data" or "System" submenu opens a search dialog for that
class of entities. You can specify a search pattern, press the top right
"Search" button (or just ENTER), and scroll through the list of results.

<p>While the "Role" and "User" entities present simple dialogs (searching just
by name), other entities can be searched by a variety of criteria. In those
cases, a "Reset" button clears the contents of the whole dialog. A new object
can be created with bottom right "New" button.

<p>In any case, the first column will contain either a "@"-link (to jump to that
object) or a "@"-button (to insert a reference to that object into the current
form).

<p>By default, the search will list all database objects with an attribute value
greater than or equal to the search criterion. The comparison is done
arithmetically for numbers, and alphabetically (case sensitive!) for text. This
means, if you type "Free" in the "City" field of the "Customer/Supplier" dialog,
the value of "Freetown" will be matched. On the other hand, an entry of "free"
or "town" will yield no hits.

<p>Some search fields, however, show a different behavior depending on the
application:

<ul>
<li>The names of persons, companies or products allow a tolerant search,
matching either a slightly misspelled name ("Mühler" instead of "Miller") or a
substring ("Oaks" will match "Seven Oaks Ltd.").

<li>The search field may specify an upper instead of a lower limit, resulting in
a search for database objects with an attribute value less than or equal to the
search criterion. This is useful, for example in the "Order" dialog, to list
orders according to their number or date, by starting with the newest then and
going backwards.

</ul>

<p>Using the bottom left scroll buttons, you can scroll through the result list
without limit. Clicking on a link will bring up the corresponding object. Be
careful here to select the right column: Some dialogs (those for "Item" and
"Order") also provide links for related entities (e.g. "Supplier").


<h4><a name="editing">Editing</a></h4>

<p>A database object is usually displayed in its own individual form, which is
determined by its entity class.

<p>The basic layout should be consistent for all classes: Below the heading
(which is usually the same as the invoking menu item) is the object's identifier
(name, number, etc.), and then a row with an "Edit" button on the left, and
"Delete" button, a "Select" button and two navigation links on the right side.

<p>The form is brought up initially in read-only mode. This is necessary to
prevent more than one user from modifying an object at the same time (and
contrary to the previous PicoLisp Java frameworks, where this was not a problem
because all changes were immediately reflected in the GUIs of other users).

<p>So if you want to modify an object, you have to gain exclusive access by
clicking on the "Edit" button. The form will be enabled, and the "Edit" button
changes to "Done". Should any other user already have reserved this object, you
will see a message telling his name and process ID.

<p>An exception to this are objects that were just created with "New". They will
automatically be reserved for you, and the "Edit" button will show up as "Done".

<p>The "Delete" button pops up an alert, asking for confirmation. If the object
is indeed deleted, this button changes to "Restore" and allows to undelete the
object. Note that objects are never completely deleted from the database as long
as there are any references from other objects. When a "deleted" object is
shown, its identifier appears in square brackets.

<p>The "Select" button (re-)displays the search dialog for this class of
entities. The search criteria are preserved between invocations of each dialog,
so that you can conveniently browse objects in this context.

<p>The navigation links, pointing left and right, serve a similar purpose. They
let you step sequentially through all objects of this class, in the order of the
identifier's index.

<p>Other buttons, depending on the entity, are usually arranged at the bottom of
the form. The bottom rightmost one should always be another "Edit" / "Done"
button.

<p>As we said in the chapter on <a href="#scrolling">Scrolling</a>, any button
in the form will save changes to the underlying data model. As a special case,
however, the "Done" button releases the object and reverts to "Edit". Besides
this, the edit mode will also cease as soon as another object is displayed, be
it by clicking on an object link (the pencil icon), the top right navigation
links, or a link in a search dialog.


<h4><a name="btnLinks">Buttons vs. Links</a></h4>

<p>The only way to interact with a HTTP-based application server is to click
either on a HTML link, or on a submit button (see also <a
href="#ctlFlow">Control Flow</a>). It is essential to understand the different
effects of such a click on data entered or modified in the current form.

<ul>
<li>A click on a link will leave or reload the page. Changes are discarded.
<li>A click on a button will commit changes, and perform the associated action.
</ul>

<p>For that reason the layout design should clearly differentiate between links
and buttons. Image buttons are not a good idea when in other places images are
used for links. The standard button components should be preferred; they are
usually rendered by the browser in a non-ambiguous three-dimensional look and
feel.

<p>Note that if JavaScript is enabled in the browser, changes will be
automatically committed to the server.

<p>The enabled or disabled state of a button is an integral part of the
application logic. It must be indicated to the user with appropriate styles.


<p><hr>
<h3><a name="dataModel">The Data Model</a></h3>

<p>The data model for this mini application consists of only six entity classes
(see the E/R diagram at the beginning of "app/er.l"):

<ul>
<li>The three main entities are <code>+CuSu</code> (Customer/Supplier),
<code>+Item</code> (Product Item) and <code>+Ord</code> (Order).

<li>A <code>+Pos</code> object is a single position in an order.

<li><code>+Role</code> and <code>+User</code> objects are needed for
authentication and authorization.

</ul>

<p>The classes <code>+Role</code> and <code>+User</code> are defined in
"@lib/adm.l". A <code>+Role</code> has a name, a list of permissions, and a list
of users assigned to this role. A <code>+User</code> has a name, a password and
a role.

<p>In "app/er.l", the <code>+Role</code> class is extended to define an
<code>url&gt;</code> method for it. Any object whose class has such a method is
able to display itself in the GUI. In this case, the file "app/role.l" will be
loaded - with the global variable <code>*ID</code> pointing to it - whenever an
HTML link to this role object is activated.

<p>The <code>+User</code> class is also extended. In addition to the login name,
a full name, telephone number and email address is declared. And, of course, the
ubiquitous <code>url&gt;</code> method.

<p>The application logic is centered around orders. An order has a number, a
date, a customer (an instance of <code>+CuSu</code>) and a list of positions
(<code>+Pos</code> objects). The <code>sum&gt;</code> method calculates the
total amount of this order.

<p>Each position has an <code>+Item</code> object, a price and a quantity. The
price in the position overrides the default price from the item.

<p>Each item has a number, a description, a supplier (also an instance of
<code>+CuSu</code>), an inventory count (the number of these items that were
counted at the last inventory taking), and a price. The <code>cnt&gt;</code>
method calculates the current stock of this item as the difference of the
inventory and the sold item counts.

<p>The call to <code>dbs</code> at the end of "app/er.l" configures the physical
database storage. Each of the supplied lists has a number in its CAR which
determines the block size as (64 &lt;&lt; N) of the corresponding database file.
The CDR says that the instances of this class (if the element is a class symbol)
or the tree nodes (if the element is a list of a class symbol and a property
name) are to be placed into that file. This allows for some optimizations in the
database layout.


<p><hr>
<h3><a name="usage">Usage</a></h3>

<p>When you are connected to the application (see <a href="#getStarted">Getting
Started</a>) you might try to do some "real" work with it. Via the "Data" menu
(see <a href="#navigation">Navigation</a>) you can create or modify customers,
suppliers, items and orders, and produce simple overviews via the "Report" menu.


<h4><a name="cuSu">Customer/Supplier</a></h4>

<p align=right>Source in "app/cusu.l"

<p>The Customer/Supplier search dialog (<code>choCuSu</code> in "app/gui.l")
supports a lot of search criteria. These become necessary when the database
contains a large number of customers, and can filter by zip, by phone number
prefixes, and so on.

<p>In addition to the basic layout (see <a href="#editing">Editing</a>), the
form is divided into four separate tabs. Splitting a form into several tabs
helps to reduce traffic, with possibly better GUI response. In this case, four
tabs are perhaps overkill, but ok for demonstration purposes, and they leave
room for extensions.

<p>Be aware that when data were modified in one of the tabs, the "Done" button
has to be pressed before another tab is clicked, because tabs are implemented as
HTML links (see <a href="#btnLinks">Buttons vs. Links</a>).

<p>New customers or suppliers will automatically be assigned the next free
number. You can enter another number, but an error will result if you try to use
an existing number. The "Name" field is mandatory, you need to overwrite the
"&lt;Name&gt;" clue.

<p>Phone and fax numbers in the "Contact" tab must be entered in the correct
format, depending on the locale (see <a href="#telFields">Telephone
Numbers</a>).

<p>The "Memo" tab contains a single text area. It is no problem to use it for
large pieces of text, as it gets stored in a database blob internally.


<h4><a name="item">Item</a></h4>

<p align=right>Source in "app/item.l"

<p>Items also have a unique number, and a mandatory "Description" field.

<p>To assign a supplier, click on the "+" button. The Customer/Supplier search
dialog will appear, and you can pick the desired supplier with the "@" button in
the first column. Alternatively, if you are sure to know the exact spelling of
the supplier's name, you can also enter it directly into the text field.

<p>In the search dialog you may also click on a link, for example to inspect a
possible supplier, and then return to the search dialog with the browser's back
button. The "Edit" mode will then be lost, however, as another object has been
visited (this is described in the last part of <a href="#editing">Editing</a>).

<p>You can enter an inventory count, the number of items currently in stock. The
following field will automatically reflect the remaining pieces after some of
these items were sold (i.e. referenced in order positions). It cannot be changed
manually.

<p>The price should be entered with the decimal separator according to the
current locale. It will be formatted with two places after the decimal
separator.

<p>The "Memo" is for an arbitrary info text, like in <a
href="#cuSu">Customer/Supplier</a> above, stored in a database blob.

<p>Finally, a JPEG picture can be stored in a blob for this item. Choose a file
with the browser's file select control, and click on the "Install" button. The
picture will appear at the bottom of the page, and the "Install" button changes
to "Uninstall", allowing the picture's removal.


<h4><a name="order">Order</a></h4>

<p align=right>Source in "app/ord.l"

<p>Oders are identified by number and date.

<p>The number must be unique. It is assigned when the order is created, and
cannot be changed for compliance reasons.

<p>The date is initialized to "today" for a newly created order, but may be
changed manually. The date format depends on the locale. It is YYYY-MM-DD (ISO)
by default, DD.MM.YYYY in the German and YYYY/MM/DD in the Japanese locale. As
described in <a href="#timeDateFields">Time &amp; Date</a>, this field allows
input shortcuts, e.g. just enter the day to get the full date in the current
month.

<p>To assign a customer to this order, click on the "+" button. The
Customer/Supplier search dialog will appear, and you can pick the desired
customer with the "@" button in the first column (or enter the name directly
into the text field), just as described above for <a href="#item">Item</a>s.

<p>Now enter order the positions: Choose an item with the "+" button. The
"Price" field will be preset with the item's default price, you may change it
manually. Then enter a quantity, and click a button (typically the "+" button to
select the next item, or a scroll button go down in the chart). The form will be
automatically recalculated to show the total prices for this position and the
whole order.

<p>Instead of the "+" or scroll buttons, as recommended above, you could of
course also press the "Done" button to commit changes. This is all right, but
has the disadvantage that the button must be pressed a second time (now "Edit")
if you want to continue with the entry of more positions.

<p>The "x" button at the right of each position deletes that position without
further confirmation. It has to be used with care!

<p>The "^" button is a "bubble" button. It exchanges a row with the row above it.
Therefore, it can be used to rearrange all items in a chart, by "bubbling" them
to their desired positions.

<p>The "PDF-Print" button generates and displays a PDF document for this order.
The browser should be configured to display downloaded PDF documents in an
appropriate viewer. The source for the postscript generating method is in
"app/lib.l". It produces one or several A4 sized pages, depending on the number
of positions.


<h4><a name="reports">Reports</a></h4>

<p align=right>Sources in "app/inventory.l and "app/sales.l"

<p>The two reports ("Inventory" and "Sales") come up with a few search fields
and a "Show" button.

<p>If no search criteria are entered, the "Show" button will produce a listing
of the relevant part of the whole database. This may take a long time and cause
a heavy load on the browser if the database is large.

<p>So in the normal case, you will limit the domain by stating a range of item
numbers, a description pattern, and/or a supplier for the inventory report, or a
range of order dates and/or a customer for the sales report. If a value in a
range specification is omitted, the range is considered open in that direction.

<p>At the end of each report appears a "CSV" link. It downloads a file with the
TAB-separated values generated by this report.

</body>
</html>