Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: How to make everything I create Upper Case?

I am currently using CSS to change everything I write to upperCase when I create an entry, but that is not enough. When I save things, the text shown in the text fields is upper case, but the real value that Grails stores stays in lower case.

I am assuming I'd need to change something in the controller or anything.

Maybe transforming the $fieldValue CSS could work??

Any ideas would help!

Thnks!

like image 465
randomizertech Avatar asked Oct 25 '10 15:10

randomizertech


People also ask

How do you make a string all upper cases?

The toUpperCase() method converts a string to uppercase letters. The toUpperCase() method does not change the original string.

How do you make upper and lower case?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.


2 Answers

You could just write setters for your domain object?

class Domain {
 String aField

 void setAField( String s ){
   aField = s?.toUpperCase()
 }
}
like image 92
tim_yates Avatar answered Nov 03 '22 01:11

tim_yates


Using annotations is cleanest approach

import org.grails.databinding.BindingFormat
class Person {
    @BindingFormat('UPPERCASE')
    String someUpperCaseString

    @BindingFormat('LOWERCASE')
    String someLowerCaseString
}

Here is link for it: Grails doc for data binding

like image 34
Priyanshu Chauhan Avatar answered Nov 03 '22 01:11

Priyanshu Chauhan