JSTL Agent identification
So converting NT2.2 to be IE6 friendly was a kick in the teeth... and as Dustin posted earlier, it would have been nice to throw up a warning window and let them see the horror or an IE6 rendering job. However we coded it up to be usable in IE6 and in the process had to rewrite some of the homepage. At first I used the ugly <![if IE 6]> // do something magical <![endif]--> tags, but they caused Safari to explode on itself. So I went back did a quick study and came out with a JSTL solution, and then modded it with Drew to get it working.
Using JSTL you can get the browser through the user-agent string in the URL request header. Like this:
<c:set var="browser" value="${header['User-Agent']}" scope="page"/> |
You can see that I used a c:set to get the 'User-Agent' string and set the variable 'browser' to that value.
Now we just need to set up a c:choose to determine the path of IE 6 or other browser types using the indexOf function in the JSTL 'fn' library. So a quick c:choose statement would look like this.
<c:set var="browser" value="${header['User-Agent']}" scope="page"/> <c:choose> <c:when test="${!empty browser && fn:indexOf(browser, 'MSIE 6') >= 0}"> NOT EMPTY </c:when> <c:otherwise> EMPTY </c:otherwise> </c:choose> |
In the 'c:when test' you can see that the indexOf ends with a '>=0', this is because indexOf returns an INT, which is treated Boolean-esque in this case (it's not a Boolean, but the way we are using it resembles a Boolean).
Don't forget that when using the JSTL fn and c tag libraries you need to include them in your jsp file. use the following at the top of your page to use these excellent tag-libs.
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> |
If you have any questions, leave'em in the comments
.
Print This Post
Quick reminder on CodeBox-ing
Every once in a while one of us logs on and would like to post some code... then we forget how to make it pretty, so here are some quick instructions for posting code here... (most of this is taken directly from the codebox plugin page.
In the "HTML" or code view of posting here in wordpress, add " <pre lang="LANGUAGE" line="1" file="download.txt" colla="+">" and then start coding (or paste your code in), when finished end it with a "</pre>" and you'll be set. I'm not sure if it's fixed or a bug or what, but if you are coding on the HTML tab, and put in your pre-tag and then switch to Visual, it'll break the pre-tag. So be careful with that... For options (parameters), use the following:
lang="LANGUAGE"-LANGUAGEis a GeSHi supported language syntax.file="download.txt"- Thefilewill create a code downloading attribute.line="N"- TheNis the starting line number.colla="+/-"- The+/-will expand/collapse the codebox.line,file,collais optional.
the GeSHi langs are:
- Actionscript
- ADA
- Apache Log
- AppleScript
- ASM
- ASP
- AutoIT
- Backus-Naur
- Bash
- BlitzBasic
- C
- C for Macs
- C#
- C++
- CAD DCL
- CadLisp
- CFDG
- ColdFusion
- CSS
- Delphi
- DIV
- DOS
- Eiffel
- Fortran
- FreeBasic
- GML
- Groovy
- HTML
- Inno
- IO
- Java
- Java 5
- Javascript
- LaTex
- Lisp
- Lua
- Microprocessor
- mIRC
- MySQL
- NSIS
- Objective C
- OCaml
- OpenOffice BASIC
- Oracle 8 SQL
- Pascal
- Perl
- PHP
- PL/SQL
- Python
- Q(uick)BASIC
- robots.txt
- Ruby
- SAS
- Scheme
- SDLBasic
- Smalltalk
- Smarty
- SQL
- T-SQL
- TCL
- thinBasic
- Uno IDL
- VB.NET
- Visual Basic
- Visual Fox Pro
- Winbatch
- X++
- XML
- z80 ASM
Enjoy...
Print This Post
JavaScript Conditional Compilations
I don't think it's any secret amongst Team Awesome or it's affiliates that I hate IE (in fact I'm pretty sure we all do) and more specifically I hate IE6, so everytime we code a new site I'm all for not supporting IE6, my motto...."punish the IE6 losers, I mean users, I mean losers" but I'm far from getting my way. Even though it appeared I might with NT2.2, ultimatley I was defeated. And it's kinda sad to because if we got away from that more than half of those who are still on IE6 would upgrade because they would realize they are behind. Anyhow in an effort to find a polite way to explain to those poor suckers that there are better more advanced browsers out there I found a way to use JavaScript to detect the javascript version of the users browser and if that version matches IE6 display a single alert box to inform them of their folley. Sure there are other ways but I found this one kinda interesting.
<script type="text/javascript"> /*@cc_on /*@if(@_jscript_version < 5.7) alert('We have detected that you are using an older browser, for a better user experience please upgrade your browser to IE7 or something totally better altogether like Firefox or Safari, or even Chrome or the PS3 browser for crying out loud.'); @end @*/ </script> |
for more information on Conditional Compilations go Here
For more informatoin on the PS3 Browser go Here
Print This Post
Loop through nothing.
We all know that using jstl we can us a <c:forEach...> to loop through just about anything, for example in the new NT2.2 we used a loop through all SKUs to grab gallery images for all apparel products.
<c:forEach var="items" items="${product.publishedItems}"> |
This is great but required all publishedItems in order for the loop to be effective.
But what if you want to loop through nothing? I know I know, sounds like it could be pretty useless but it's not. What I'm talking about is what if you want to run a loop 5 times but have nothing to loop through? Well it's pretty simple but difficult to find any documentation on, hence this post. So before you go dropping scriplet (or as I like to call it, "Nava" or "NinJava") code on your .jsp and have one of your teammates commit treason, read on Josephine, read on.
Brace yourself, here it is.
<c:forEach begin="1" end="8"> |
Pretty neat huh, your loop starts at one and ends at 8, one thing I've yet to find is an effective way to break the loop using jstl if necessary. Ninja said something about setting a flag and I did that but at second glance it's not quite as effective as I had originally hoped.
Print This Post
Mini Web Dev Training – Nefarious Video Tactics
So Branden was asking me this morning for help on acquiring a news video clip from msnbc.com. There are several and many ways one could tackle this issue. He had already aquired the video, but the audio wasn't coming with it. Now I'm not 100% sure on how he grabbed the video (I didn't really ask), but I'm thinking he used a screen recorder. That usually works, but sometimes it doesn't capture the audio, and that can be for a myriad of reasons. So what did I do to aquire the video for him?
1- Go and grab TubeMaster Plus. This is a handy little tool that has a built in browser that lets you surf to a page and then grab any streaming video (complete with audio) from it. While the interface is a bit clunky, it is somewhat intuitive. It also does have a built-in "tutorial" site built into it to help you get started. The biggest help for me was if I had been told it was a stand-alone client, meaning no IE of FF needed, just throw the link on the main page and it will use the internal browser to render the page and aquire the video. Note that the video should come down as an FLV, you can either convert it inside TMPlus, or use your favorite software to do the encoding.
2- Go and get MediaInfo. This is a handy little app that will tell you the bitrate, video resolution, fps, etc of any media file. Open the FLV in MediaInfo and checkout the video bit-rate, the frame-size, and the audio encoding. Generally I leave this window up.
3- Use SUPER to re-encode/transcode the file into a format more suitable for your use. SUPER is a rough program to download, I'm not sure if the authors actually enjoy torture, or just can't build a web-page to save their own life, so instead of grabbing it at the offical source, grab SUPER from somewhere trustworthy, like AfterDawn.com (yes the site name sounds like it could be naughty, but it's not, they've been on the scene with video encoding since just about the birth of AngelPotion, and if you got that reference, you just gained a little of my respect
).
4- When SUPER is done encoding, enjoy your video. A simple solution to your video ripping problems.
Other sites/tools you can use to aquire your favorite online videos.
- YouTube Ripper (webservice) - Just paste the YouTube link in the box and then right-click and save the flv.
- LiveHTTPHeaders - (Firefox plugin, manual, and painful)
- Fiddler2/httpspy - (IE plugins, manual, and painful - note that httpspy has become difficult to find... extremely difficult to find, and there is another program out in the wild that is NOT the same. Consult the Ninja on the offical version)
If you need pictures I can create an actual Developer Training (with a minisite), but for now, I'm hoping the text will do. If you have questions or need more examples etc. Leave a comment and I'll get on it.
Print This Post