Monday, 15 July 2013

grails 2.0 - GSP- formatDate tag issue handling null date -



grails 2.0 - GSP- formatDate tag issue handling null date -

i used collection of date field controller gsp using tag - @ times there blanks , invalid info , throws error. how should handle null pointer??

code < g:formatdate format="yyyy-mm-dd" date="$ {objectinstance?.expirydate} "/>

i tried using -- ${objectinstance?.expirydate?.format("mm/dd/yyyy")} , no luck. in anticipation.

vignesh,

here couple of potential solutions (assuming ok showing nil or alternate text when date null):

${try{objectinstance?.expirydate?.format('mm/dd/yyyy')}catch(e){''}}

or, handle in controller (my preferred method) using same code above without ${} wrapping , set model property.

[expirydateformatted: try{objectinstance?.expirydate?.format('mm/dd/yyyy')}catch(e){''}]

give seek , see if work you.

after speaking vignesh turns out expirydate string , not date. below solution work string value.

${try{new date().parse('yyyy-mm-dd', objectinstance?.expirydate).format('mm/dd/yyyy')}catch(e){''}}

grails-2.0 gsp

No comments:

Post a Comment