Disabling HTML elements (in JSPs) with JSTL's "c:if"

I've been doing some Spring-based web forms work recently and one area of interest was around disabling certain input fields until particular values were set in the form-backing object. I wanted to ensure that particular radio buttons were disabled if the value was not what I expected.

Below is a statically disabled Spring radiobutton:

<form:radiobutton path="name" disabled="true"/>
For example's sake, I wanted to disabled the button if the name field of the form-backing object was "beacock", so what I needed was a boolean variable which captured the output of my particular test:
<c:if test="details.name eq 'beacock'">
<c:set var="isMe" value="true"/>
I could then use the above isMe variable in the following:
<form:radiobutton path="name" disabled="${isMe}"/>
Simple huh? But you can go a step further in the strive for clean code, the tag can take an optional var parameter which is a holder for the outcome of the boolean expression:
<c:if test="${details.name eq 'beacock'}" var="isMe"/>
So now the whole thing becomes:
<c:if test="${details.name eq 'beacock'}" var="isMe"/>
<form:radiobutton path="name" disabled="${isMe}"/>
Although you can perform complex expressions in the ${} tags, you can use the ternary operator:
value="${isMe ? 'Andrew Beacock' : 'Someone Else'}"
Here are a few more things I've found you can use as well:
${not isMe}
${not isMe or someOtherVariable}
A very good reference for all things JSTL is the JSTL quick reference - an appendix of one of the Manning books. Also the TLD documentation of the Spring Form Tag library is full of all the optional stuff.

Technorati Tags: , , , ,

jQuery has a new funky API browser

Head over to api.jquery.com and check out the rather swish new way to browse it's API reference documentation.

Oh and of course it's powered by jQuery - what a wonderful way to show what you can do with the jQuery JavaScript Library!

Technorati Tags: , ,

JustinGuitar.com - a fantastic resource for learning the guitar - and it's free!

Back in August I decided that I wanted to learn the guitar. It's been an instrument that I've always wanted to play and so I thought "why not just try to learn it?". I spoke to a friend who lent me his electric so now I just needed some lessons...

After a search on YouTube I found a few half-decent videos and then I discovered Justin Sandercoe's excellent JustinGuitar.com tuition site.

It's packed full of lessons on almost everything and Justin has an excellent teaching manner - makes watching his videos entertaining and informative. I've learnt so much from watching them that it's pretty much the only place on the net that I go for guitar advice - his forums are also an excellent place to get more advice from other guitarists.

Although Justin's content is free you can donate cash if you wish to help support him as he films these wonderful instructional videos.

When people ask me if I'm having lessons I say "yes, from JustinGuitar.com"!

Technorati Tags: , , ,