Using Middleware to build web pages

27 April 2009
Everyone is aware of middleware like php, net, ruby, lasso, Web Objects etc. to add logic to web pages, but do you use the same processes to make the construction of your pages easier?

From time to time a client will request a particular function that they desire for their web site and you set about the logic to achieve their request. Sometimes it occurs that the request is similar to one which you had in the past and you can re-purpose the logic for the new application. However certain aspects of web development lend themselves to using the same logic in the scripting environment to actually build the logic for a web page. An example of this came up in a recent site where the original brief called for a form which amongst other items contained a field which required the user to supply the business sector in which they operated.

Initially the site went live with a simple text field and users entered their information in the manner they saw fit, of course this can be a nightmare when you attempt to analyse the data based on the users input. In this regard some entries on the project were far from useful, occasionally the user adding an entry which was completely out of context. For example on more than one occasion the user added the sector information as their location!

We contacted the client and suggested a more structured approach using criteria from their own analysis software, this provided us with a massive list, which they wanted to show in an option menu. No doubt you have come across such an option list which is so long that getting to your choice is an unwieldly process. We suggested breaking the list into categories and sub-categories and using a javascript to populate the sub-category based on the initial choice, a common use for javascripts on many web sites. They agreed and we looked at the change, taking an existing script which used counties as the main category and principle cities within the county as a sub-category. Simple swop the data, job done!

But is this the best way of proceeding? The data is in a database table with two fields which are relevant to the form, principal sector: say, "Auctions" sub sector a list of five items, "Auctioneers - General, Auctioneers - Antiques & Fine Art ... etc. This can be readily achieved using a database query in the web page, but it puts heavy demands on the server, given the number of hits being received, to deliver on each request a massive list of over 1,500 options. So you could hard code the data into the page, both long winded and drudgingly boring, this would have the advantage of reducing the load on the server, but aside from the tedium of building it, every time the list changes you have to edit the javascript, with a good chance of mistakes creeping in.

So what else can be done to simplify the job. Well how about writing the code to extract the data from the database, which renders the web page form item, then getting the same middleware logic to write this to a file which can be included in the form on the page. When the client updates the listing (a backend facility), you re-run the process and you have a new option menu in seconds, no mistakes either! You zapped them the first time you produced the script! By putting the database connections in the logic as variables you can re-use the logic on any number of similar examples. This might just keep you ahead of the game for a few moments!

 

blog comments powered by Disqus