22 August, 2005

CSS as JSP

The Problem

I've been working on refactoring a project from tables to a table-less design with CSS. The stated benefit (with which I agree wholeheartedly) is that using tables for layout of non-tabular data (that is, using tables to position blocks of text) is improper because it is using the wrong tool for the job. Any artisan (woodworker, metalsmith, sculptor) would tell you this is a huge no-no, but in web design, it's gone unchallenged for virtual centuries (i.e. a few years). But the "it's-just-bad-art-and-bad-zen" argument isn't the whole story: alternative browsers (cell phones, audiobrowsers for the deaf, etc) have no idea what these tables mean, and will therefore confuse their users. The problem is that though CSS is standardized, some broswers (most notoriously, IE) don't conform to the standard.

The Established Solution

So far, people have been adding hacks to their CSS to get around browser differences. Things like the star html hack and the mac backslash hack are ingenious, but they impede development. They're hard for future programmers to understand (even with liberal comments), and they're logically messy. (No self-respecting C++ programmer would write

  width = 100;
  callBackSetWidth(120);  //Linux platforms before
                          //1997 don't support this,
                          //so they get the value 100
It's just ugly.)

My Solution

I came upon my solution by accident. I have been using the .jsp extension for my CSS files for a while now for the sole purpose of being able to use the <c:url> tag. If I use an image for a background, I don't want the link to have to reference my project name - epecially since the context may change to root at deployment.

Because the CSS files were already dynamically generated, I thought of doing browser dependency with tags. I've got
<c:set var="user_agent" value="${headerValues['user-agent'][0]}" />

<c:choose>
  <c:when  test="${fn:startsWith(user_agent, 'Mozilla/5.0')}">
    <%-- Firefox 1.0, Gecko, etc --%>
    <c:set var="firefox" value="${true}" />
    <c:set var="ie" value="${false}" />
    <c:set var="app_width" value="760" />
  </c:when>
  <c:otherwise>
    <%-- IE 6 --%>
    <c:set var="firefox" value="${false}" />
    <c:set var="ie" value="${true}" />
    <c:set var="app_width" value="762" />
  </c:otherwise>
</c:choose>
at the top of the file. You could easily have more cases if you need to support more browsers. Notice first the "ie" and "firefox" variables. These can be used by tags later for browser-specific settings. Also notice the global variable app_width; this is a nice way of promoting reuse (constants are our friends - it'd sure be nice to be able to make 'em final in the page scope, though) while allowing differences between browsers.

18 comments:

Anonymous said...

[B]NZBsRus.com[/B]
Dont Bother With Crawling Downloads Using NZB Files You Can Instantly Search High Quality Movies, Console Games, MP3 Albums, Software & Download Them @ Rapid Speeds

[URL=http://www.nzbsrus.com][B]Usenet Search[/B][/URL]

Anonymous said...

Through Our Risqu‚ Prices at www.Pharmashack.com, The Phenomenal [b][url=http://www.pharmashack.com]Online Posologist's [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Incontestable Mammoth Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Corbel a Ginormous Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] Because of the duration of Your Regimen ! We Vend Epithet [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

Making money on the internet is easy in the hush-hush world of [URL=http://www.www.blackhatmoneymaker.com]blackhat tools[/URL], You are far from alone if you haven’t heard of it before. Blackhat marketing uses alternative or not-so-known avenues to build an income online.

Anonymous said...

Eure Seite ist echt schoen, aber da wir auch eine heisse Seite haben, auf der es Zwar um den [url=http://www.sexcamamateure.net][b]Livesex[/b][/url] geht, aber dennoch das ein bestandteil des Internets ist, moechte ich Euch die Seite auch mal vorstellen.
Hier sind eben ganz private Frauen die mit einer Livecam zu hause sitzen um hemmungslos den [url=http://www.sexcamamateure.net][b]Sex[/b][/url] zu erleben. Mit einem Chat hast Du die Chance diese Sexgirls live zu sehen und mit ihnen ueber den Chat vor
der Sexcam zu schreiben. Hier ist sie nun die geile und hemmungslose Seite fuer private Frauen die vor ihren tabulosen [url=http://www.sexakt.org][b]Sexcams[/b][/url] auf Dich warten.

Schau rein und geniesse die Show!

Anonymous said...

Hello,

Thanks for sharing the link - but unfortunately it seems to be down? Does anybody here at 100essays.blogspot.com have a mirror or another source?


Cheers,
Harry

Anonymous said...

top [url=http://www.c-online-casino.co.uk/]c-online-casino.co.uk[/url] hinder the latest [url=http://www.realcazinoz.com/]casino[/url] free no set aside hand-out at the foremost [url=http://www.baywatchcasino.com/]baywatchcasino
[/url].

Anonymous said...

top [url=http://www.001casino.com/]001[/url] coincide the latest [url=http://www.realcazinoz.com/]casino games[/url] unshackled no set aside hand-out at the leading [url=http://www.baywatchcasino.com/]baywatch casino
[/url].

Anonymous said...

[url=http://casodex-bicalutamide.webs.com/]Androbloc
[/url] Casodex buy
comprare Bicalutamide
Bicamide

Anonymous said...

[url=http://cyclosporine.webs.com]Sandimmune online
[/url] ciclosporina cane
ciclosporina dosis perros
sandimmun neoral y embarazo

Anonymous said...

[url=http://www.realcazinoz.com]online casino[/url], also known as effectual casinos or Internet casinos, are online versions of wont ("chunk and mortar") casinos. Online casinos ok gamblers to feign and wager on casino games from start to waste the Internet.
Online casinos habitually submit on the bazaar odds and payback percentages that are comparable to land-based casinos. Some online casinos directing higher payback percentages in the line of downheartedness battalion games, and some drill the low-down deviant payout correlation audits on their websites. Assuming that the online casino is using an meetly programmed unpremeditatedly uncounted generator, suggest games like blackjack clothed an established column edge. The payout emend during these games are established distant non-standard repair to the rules of the game.
Uncountable online casinos permission minus or possessions their software from companies like Microgaming, Realtime Gaming, Playtech, Supranational Conspiracy Technology and CryptoLogic Inc.

Anonymous said...

[url=http://www.dailystrength.org/people/2641034/journal]sacs longchamps[/url] Where we once trusted the big dog food companies. we now Cheapest Designer Women Mulberry Medium Bayswater Leather Tote Bag Light Coffee,Mulberry handbags from mulberry factory shop are on sale know that they are mostly just businesses, interested first in profits and only secondarily in the dogs and their owners. Cutting corners with second rate ingrdients will still show up as meat on the label perhaps but not fully decribe the condition of that meat.
[url=http://www.freewebsite-service.com/longchampbagsd/Blog.php]longchamp soldes[/url] The Travelling Light bag from Seat to Summit is an ultralight travel duffle with an incredible volume and strength enough to carry a heavy load. Use it New Fashion Mulberry Women's Mini Alexa Leather Satchel Light Coffee Bag, Mulberry Outlet online offer you high level quality Mulberry Bags at a low price. as carry-on baggage for airline travel, a carry-all for impromptu excursions or just going to the gym; it's also an obvious choice as a spare bag on any trip. Zippered main compartment with carry handles.
[url=http://www.nexopia.com/users/longchampplia/blog]longchamp soldes[/url] In shoppers will be charged 5p per bag from this October, and a consultation on charging for bags kicked off in Northern Ireland last week. John Griffiths, Welsh environment minister, said a charge was the best way to drive down carrier use, as voluntary agreements with retailers would not achieve enough. He said: "These figures show a real difference between carrier bag use in Wales and that in other parts of the UK where no mandatory charge is planned. Replica Affordable Mulberry Women's Daria Leather Belt Black Bag supply cheap, Mulberry Handbags UK Online Shopping Outlet Store handbags are inspired by the design of authentic designer handbags. We can find replicas for all top brands. When you are picking replica handbags for your girl friends make sure that you find the latest model replicas. This is the Brighton handbags French connection. A new interpretation of classic Euro design house makes this a very popular. Features: 12.5 "straps, inside zippered pocket, keychain, ziptop closure, two side pockets with magnetic lid closure, back pocket, custom Brighton and a striped lining," feet "at the bottom of handbag..

Anonymous said...

buy tramadol online no prescription cod tramadol 50mg vs 100mg - buy tramadol no prescription uk

Anonymous said...

http://www.achildsplace.org/banners/tramadolonline/#6091 buy tramadol online cod - buy tramadol with paypal

Anonymous said...

buffalo ny dating sites [url=http://freeinternetdating.info/dating/dane-cook-dating-jokes]dane cook dating jokes[/url] waynesville mo dating
americans members dating site all free http://freeinternetdating.info/romance/free-on-line-reads-romance read double your dating free
advice dating a slut [url=http://freeinternetdating.info/matchmaker/egyptian-matchmaker]blog boyfriend dating jeremy mccarthy[/url] adriana lima dating

Anonymous said...

z e software co http://downloadoemsoftware.co.uk/product-36273/CoffeeCup-Web-Image-Studio-1-0 adobe recording software [url=http://downloadoemsoftware.co.uk/product-33085/Sophos-SafeGuard-PortAuditor-3-2]dv capture software microsoft[/url] sfis software
[url=http://downloadoemsoftware.co.uk/product-23096/Filemaker-9-Server-Advanced-Mac]Filemaker 9 Server Advanced [Mac] - Download OEM, Software Sale, OEM Software[/url] adelphia cable modem software
[url=http://downloadoemsoftware.co.uk/es/category-9/Antivirus-y-seguridad?page=5][img]http://buyoem.co.uk/image/4.gif[/img][/url]

Anonymous said...

american dating sites with chatroom http://loveepicentre.com korean dating sites
dating two people at once [url=http://loveepicentre.com]speed dating malaysia[/url] talking dating relationship
100 uk dating sites [url=http://loveepicentre.com]studies about women and dating preferences[/url] raidoactive dating [url=http://loveepicentre.com/user/Je_an/]Je_an[/url] free dating sites wiltshire england

caverta said...

Nice Post Love Reading Its

kamagra 100mg

generic Viagra 100mg

Anonymous said...

Hello just wanted to give you a quick heads up. The words in your post seem to be running off the screen in Safari. I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know. The layout look great though! Hope you get the problem resolved soon. Cheers.
Prenancy Symptoms