jquery

gist JS

Monday, May 15, 2006

Travels, travails, freemarker

Spring MVC, freemarker boolean form check.


<#macro booleanFormCheck path attributes="">
<@spring.bind path/>
<input type="checkbox" id="${spring.status.expression}" name="${spring.status.expression}" value="true"
<#if spring.stringStatusValue == "true">checked="checked"</#if> ${attributes}
<@spring.closeTag/>
<#assign hiddenName = "_"+spring.status.expression/>
<input type="hidden" name="${hiddenName}">
</#macro>

First off, I must be the 100th person to write this. A little boolean formCheck that puts the hidden field in for you? spring.ftl is well and good, but how about a new bloatedSpring.ftl with lots of goodies like this one.

Printing a date that might be null in freemarker


Sounds easy right? Well, I'm sure it is, but damn if I didn't spend a half hour massaging my temples. (oh and I'm positive there's a lovely way to do this in place, but I'll be damned if I'm going to spend any more time looking.

<#macro printDate date="">
<#if date?has_content>
${date?date?string.short}
<#else>
None Provided
</#if>
</#macro>


Turning a number that's been turned into a string back into a number.


(If the number is greater than 999)
Right. So it all works fine. You've got a nice drop-down select. Now you (silly thing that you are) want a confirmation page, but rather than telling them they've selected pop-rocks flavor #38, you want to tell them that they've selected flavor "Rasberry Crush", so pop that back in the referenceData and off you go...

up until you get to flavor 1000 (or should I say "1,000"). Then you spend a while sitting in front of the people you convinced ot ditch jsp, helplessly trying to change you internationalization settings to take out commas and having simple no luck with ?int and it's ilk... until you find... ?c

<#macro printLookup array element>
<#if element?exists && element?string == "-1">
None Provided
<#else>
${array[element?c]}
</#if>
</#macro>

Happily this also solves other infuriating 9300->"9300"->(int)9,300 freemarker bind exception explosions:

<#macro formInputInt path attributes="" fieldType="text" >
<@spring.bind path/>
<input type="${fieldType}" id="${spring.status.expression}" name="${spring.status.expression}" value="<#if fieldType!="password">${spring.status.value?default(0)?c}</#if>" ${attributes}
<@spring.closeTag/>
</#macro>
<#macro formHiddenInputInt path attributes="" >
<@formInputInt path, attributes, "hidden"/>
</#macro>

Wednesday, May 03, 2006

Books - Spring 06 Edition

Books aquired:
  • Bully for Brontasaurus, Gould

  • The collected pdf's of John Searle


Books held in hand significantly at bookstore:

Books read:
  • The System of the World, Neal Stephenson



Well, the beast that is the Baroque Series is finalement slew. It is a true testament to a work of fiction that the last 80 pages of your nigh-on 3000 page odyssey are things to savor and nothing at all like the grim dregs of a cup of flip gone wrong. One can only hope that Eliza de la Zeur will return in another time. I am very much unfinished being in love with her.

The Searle bears explaining I suppose.

Oh and all apologies to Nick Hornby. My use of your lovely format is intended only for personal use. All other use is expressly unintended and wholy unexpected as you can clearly see by the number of people that frequent this blog.