jueves, julio 31, 2008
Messagerie instantanée avec Google Talk et Grails | odelia technologies
Messagerie instantanée avec Google Talk et Grails | odelia technologies: "Messagerie instantanée avec Google Talk et Grails"
Publicado por SiTo en 7/31/2008 05:03:00 p. m. 0 comentarios
JT Dev » Blog Archive » Shorter Grails textField
Shorter Grails textField
Making textFields in Grails is a bit verbose, at least if you want error highlighting and returned values on errors. This post shows a quick solution.
Problem
A full textField would be:
view plaincopy to clipboardprint?
1.
Which clearly is very verbose; you have to specify “user” twice, and “name” even three times. This verbosity also makes the view less readable.
Googling for this problem resulted in: Smarter Grails Tags (a proposal). Funny that the writer exactly sees the same problem in it, also uses the “user” domain model, and also knows Stripes where you could just use something like
view plaincopy to clipboardprint?
1.
and specify the bean name in the form. (Stripes has a very good Quick Start Guide, which also shows error highlighting.)
One of the less verbose proposed formats of textField is:
view plaincopy to clipboardprint?
1.
Implemented Solution
I found that implementing a quick version of this is surprisingly easy in Grails, it only takes for a few statements. Here is the code:
view plaincopy to clipboardprint?
1.
import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
2.
3.
// file: project/grails-app/taglib/MyTagLib.groovy
4.
class MyTagLib {
5.
// tagname "myTextField" within the "g" namespace
6.
def myTextField = {attrs ->
7.
// If a controller returned the bean, and the field has an error,
8.
// then "errors" will be returned as HTML class, otherwise the class will be empty.
9.
attrs.class = hasErrors(bean:attrs.bean, field:attrs.field, 'errors')
10.
// Retrieves the field value of the given bean to be rendered in the view.
11.
// Note: specify the bean and not the bean name. So "${user}" instead of "user"
12.
attrs.value = fieldValue(bean:attrs.bean, field:attrs.field)
13.
// Required for textField taglib. attrs.name is a keyname of the params map
14.
attrs.name = attrs.field
15.
// renders the HTML tag
16.
out << new FormTagLib().textField(attrs)
17.
}
18.
}
import org.codehaus.groovy.grails.plugins.web.taglib.FormTagLib
// file: project/grails-app/taglib/MyTagLib.groovy
class MyTagLib {
// tagname "myTextField" within the "g" namespace
def myTextField = {attrs ->
// If a controller returned the bean, and the field has an error,
// then "errors" will be returned as HTML class, otherwise the class will be empty.
attrs.class = hasErrors(bean:attrs.bean, field:attrs.field, 'errors')
// Retrieves the field value of the given bean to be rendered in the view.
// Note: specify the bean and not the bean name. So "${user}" instead of "user"
attrs.value = fieldValue(bean:attrs.bean, field:attrs.field)
// Required for textField taglib. attrs.name is a keyname of the params map
attrs.name = attrs.field
// renders the HTML tag
out << new FormTagLib().textField(attrs)
}
}
Usage
view plaincopy to clipboardprint?
1.
And ofcourse some CSS to highlight the error in a color. This can be put in the HTML head (or better, a seperate CSS file) :
view plaincopy to clipboardprint?
1.
Publicado por SiTo en 7/31/2008 04:51:00 p. m. 0 comentarios
jueves, julio 24, 2008
jan blog: Experience with Act as Taggable Plugin
jan blog: Experience with Act as Taggable Plugin: "Experience with Act as Taggable Plugin"
Publicado por SiTo en 7/24/2008 12:38:00 p. m. 0 comentarios
miércoles, julio 23, 2008
Screensavers - Best Of | Graphics | Smashing Magazine
Screensavers - Best Of | Graphics | Smashing Magazine: "Screensavers - Best Of"
Publicado por SiTo en 7/23/2008 02:19:00 p. m. 0 comentarios
Ext2 IFS For Windows
What's unique about this software?
It provides Windows NT4.0/2000/XP/2003/Vista with full access to Linux Ext2 volumes (read access and write access). This may be useful if you have installed both Windows and Linux as a dual boot environment on your computer.
The 'Ext2 Installable File System for Windows' software is freeware.
Publicado por SiTo en 7/23/2008 02:17:00 p. m. 0 comentarios
PosteRazor - Make your own poster!
PosteRazor - Make your own poster!: "PosteRazor"
Publicado por SiTo en 7/23/2008 01:53:00 p. m. 0 comentarios
Use your laptop as an Xbox/Xbox 360 "Wireless Adapter" on Windows XP/Vista, and Mac OSX - Instructables - DIY, How To, tech
Use your laptop as an Xbox/Xbox 360 "Wireless Adapter" on Windows XP/Vista, and Mac OSX - Instructables - DIY, How To, tech: "Use your laptop as an Xbox/Xbox 360 'Wireless Adapter' on Windows XP/Vista, and Mac OSX"
Publicado por SiTo en 7/23/2008 01:53:00 p. m. 0 comentarios
jueves, julio 17, 2008
miércoles, julio 16, 2008
Groovy , Grails and DateTime Links
rain city digest: Groovy DateTime Comparisons
Groovy Temporal Support Classes
Groovy Temporal Support Continued
Converting MS Active Directory time in human readable format with Groovy
TagLibs en Grails
IBM
developerWorks Technical library view (mastering grails)
Publicado por SiTo en 7/16/2008 03:32:00 p. m. 0 comentarios
JAVA Excel Designner
JAVA Excel Designner: "Java Excel Designer"
Publicado por SiTo en 7/16/2008 08:53:00 a. m. 0 comentarios
martes, julio 15, 2008
Jorge on Programming: grails
Jorge on Programming: grails: "Friday, July 4, 2008"
Publicado por SiTo en 7/15/2008 06:50:00 p. m. 0 comentarios
lunes, julio 14, 2008
Top 10 CSS buttons tutorial list
Top 10 CSS buttons tutorial list: "Top 10 CSS buttons tutorial list"
Publicado por SiTo en 7/14/2008 11:26:00 a. m. 0 comentarios
jueves, julio 10, 2008
miércoles, julio 09, 2008
Animated Progress Bars Using MooTools: dwProgressBar
Animated Progress Bars Using MooTools: dwProgressBar: "Form completion tracking"
Publicado por SiTo en 7/09/2008 08:29:00 a. m. 0 comentarios
martes, julio 08, 2008
lunes, julio 07, 2008
miércoles, julio 02, 2008
martes, julio 01, 2008
One pixel notched corners as used by Google Analytics (Ask the CSS Guy)
One pixel notched corners as used by Google Analytics (Ask the CSS Guy): "One pixel notched corners as used by Google Analytics"
Publicado por SiTo en 7/01/2008 05:53:00 p. m. 0 comentarios
woork: Clean and pure CSS FORM design
woork: Clean and pure CSS FORM design: "Clean and pure CSS FORM design"
Publicado por SiTo en 7/01/2008 05:53:00 p. m. 0 comentarios
Decoding raw digital photos in Linux
Decoding raw digital photos in Linux: "Decoding raw digital photos in Linux"
Publicado por SiTo en 7/01/2008 09:53:00 a. m. 0 comentarios