Get It:
Download
Change Log
Learn It:
Install
Tutorial
API Doc
Discuss It:
Mailing List
Follow It:
Code

Tutorial Part 6. Extended slot options and genpages macro

web4r provides extended slot options for a persistent class and genpages macro which generates pages to list, edit, show and delete instances of a persistent class.

Extended slot options

Genpages macro

Generated Pages and Functions

index page

customer-index

show page

customer-show

edit page

customer-new customer-edit

Examples:

Blog Application

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :web4r))

(in-package :cl-user)
(defpackage :blog (:use :cl :web4r))
(in-package :blog)

(ele:open-store *example-bdb*)

(defpclass blog ()
  ((title :length 50 :index t)
   (body  :length 3000)))

(genpages blog)

(start-server)

Customer Application

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op :web4r))
(use-package :web4r)

(in-package :cl-user)
(defpackage :customer (:use :cl :web4r))
(in-package :customer)

(ele:open-store *example-bdb*)

(defpclass customer ()
  ((name         :length 50 :label "Full Name" :size 30 :index t)
   (password     :input :password :length (8 12) :comment "8-12 characters"
                 :hide-for "^(?!/customer/edit/)")
   (email        :format :email :unique t)
   (sex          :input :radio :options ("Male" "Female"))
   (marriage     :input :select :options ("single" "married" "divorced"))
   (hobbies      :input :checkbox :options ("sports" "music" "reading"))
   (birth-date   :format :date :index t)
   (nickname     :length 50 :required nil)
   (phone-number :format "^\\d{3}-\\d{3}-\\d{4}$" :comment "xxx-xxx-xxxx" :index t)
   (zip-code     :type integer :length (5 5) :comment "5 digit" :index t)
   (note         :length 3000 :rows 5 :cols 30)
   (image        :input :file :format :image :length (1000 500000) :required nil)))
(genpages customer)

(start-server)

Note: A name of a persistent class must be a singular. (The genpages macro pluralize it when needed.)