Saturday, April 29, 2006

Database access

Our next objective was to introduce database interaction. We decided to have the following classes for it.
TabularTo show multiple records in a grid
FreeFormTo show one record with multiple fields
DataStoreTo interact with database

In addition two classes were used internally.
  • RecordSet - to hold a retrieved record
  • Column - to hold information about columns in a tabular and rows in freeform
The action class was also extended to support a call to a server side function created as a part of the page definition. To both Tabular and FreeForm, we added some Ajax like features so that:
  • A HTTP XML request can be send from the send from a client action, attached to a tabular column, which will invoke a server side function written in the page.
  • The server side function can create a class, like FreeForm, and sends it to the client
  • The FreeForm is repainted in the client
So there is a tabular portion in the screen which displays name of all the participants. There is also a FreeForm portion which displays more detail. On click on any name the data is fetched from the server side and the FreeForm is updated.

We created a database of all people attending the BarCamp at Chennai to get the page working.

The code looks like this:

module PageTabular

def showFreeform(pNameClicked)
    datastore = DataStore.new("tsgpdc2k", "ubuildmya", "sets")
    datastore.databasename = "SessionDB"

    freeform = Freeform.new
    freeform.name = "DynamicDisplay"

    style = Style.new
    style[:font_size] = 12
    style[:color] = "blue"

    liveNewsText = Text.new("")
    liveNewsText.style = style
    newsDetail = Text.new("")
    newsDetail.style = style
    presentation = Text.new("")
    presentation.style = style
 
    freeform.add("Name", "Attendee Name", liveNewsText)
    freeform.add("Details", "Attendee Details", newsDetail)
    freeform.add("Presentation", "Presentation Given", presentation)

    datastore.sql  = "select * from Attendees where name= ?"
    datastore.setParameter(1, pNameClicked)
    freeform.columns = datastore.select

    return freeform
end

def pageText
    page = Page.new(:PageTabular)

    datastore = DataStore.new("tsgpdc2k","ubuildmya","sets")
    datastore.databasename = "SessionDB"
    datastore.sql  = "select * from Attendees"

    freeformstyle = Style.new
    freeformstyle[:left] = 300
    freeformstyle[:background_color] = '#A5c3ef'

    freeform = Freeform.new
    freeform.name = "DynamicDisplay"
    freeform.width = 350
    freeform.style = freeformstyle
    freeform.valign = :top

    tabularsection1 = Tabular.new
    tabularsection1.maxRow = 100
    tabularsection1.height = 100

    style = Style.new
    style[;color] = "blue"

    name = CheckBox.new('')
    actionclass = Action.new
    actionclass.add(page, 'showFreeform', [name], [freeform])
    actionclass.add(freeform, "refresh")
    name.event[:Click] = actionclass
    name.style = style

    tabularsection1.add("Name", "Attendee Name", name)
    tabularsection1.columns = datastore.select

    page << [tabularsection1, freeform]

    return page
end
end

8 Comments:

Anonymous Anonymous said...

car insurance dallas
instant car insurance quote
car insurance broker
free car insurance quote
car insurance quote online uk
agent car company home insurance life quote rate
auto cheap insurance
agent car company home insurance life quote rate
online car insurance rate
online auto insurance quote
progressive car insurance
norwich union car insurance
aarp car insurance
compare car insurance quote
car insurance quote uk
car insurance ny
car insurance n
cheap online car insurance quote
classic car insurance
car insurance rating
affordable car insurance
classic car insurance
churchil
l car insurance

state farm car insurance
new jersey car insurance
nj car insurance
low cost car insurance online
car insurance chicago
florida car insurance
best car insurance rate

http://cheap-car-insurance.quickfreehost.com

Random Keyword: :)
free online car insurance quote

11:03 AM  
Anonymous Anonymous said...

[url=http://www.firstboots.co.uk][img]http://www.firstboots.co.uk/images/ugg-boots.jpg alt="sale ugg" title="ugg boots"[/img][/url] ugg duck boots http://www.kindboots.co.uk
[url=http://www.wholeboots.co.uk/#q7c70i50d][b]ugg[/b][/url]
[url=http://www.likeboots.co.uk/#a8q69u93s][b]ugg[/b][/url]
[url=http://www.firstboots.co.uk/#l2j48h52d][b]cheap ugg[/b][/url]

1:46 AM  
Anonymous Anonymous said...

get tlfGsHCC [URL=http://www.camera--lenses.com/]canon ef 75-300mm[/URL] , just clicks away HJhAIjqx [URL=http://www.camera--lenses.com/ ] http://www.camera--lenses.com/ [/URL]

10:10 PM  
Anonymous Anonymous said...

you definitely love ZSaHEGdV [URL=http://www.cheapguccireplica.tumblr.com/]gucci shop online[/URL] for more detail yOtkdjrR [URL=http://www.cheapguccireplica.tumblr.com/ ] http://www.cheapguccireplica.tumblr.com/ [/URL]

7:55 PM  
Anonymous Anonymous said...

you love this? WZdQyVYG [URL=http://www.replicalv.webs.com/]replica louis vuitton bags[/URL] at my estore XvHSNVEb [URL=http://www.replicalv.webs.com/ ] http://www.replicalv.webs.com/ [/URL]

11:24 PM  
Anonymous Anonymous said...

buy cpDeOtnY [URL=http://www.aaareplicahandbags.weebly.com/]designer mirror[/URL] with low price ckUHQvlI [URL=http://www.aaareplicahandbags.weebly.com/ ] http://www.aaareplicahandbags.weebly.com/ [/URL]

9:54 PM  
Anonymous Anonymous said...

you will like IIEajKYJ [URL=http://www.aaareplicahandbags.weebly.com/]aaa replica bags[/URL] for more detail NbXJhyxS [URL=http://www.aaareplicahandbags.weebly.com/ ] http://www.aaareplicahandbags.weebly.com/ [/URL]

3:41 PM  
Anonymous Anonymous said...

check RqDDzkXc [URL=http://www.cheapdesigner--handbags.weebly.com/]replica handbags[/URL] for more SMNtOTuD [URL=http://www.cheapdesigner--handbags.weebly.com/ ] http://www.cheapdesigner--handbags.weebly.com/ [/URL]

11:42 PM  

Post a Comment

<< Home