javascript - Binding real number values to Grails domain attributes (values sent by Dojo widgets) -



javascript - Binding real number values to Grails domain attributes (values sent by Dojo widgets) -

i using dojo 1.9 grails 2.3.9.

the dojo numbertextbox widget - utilize in forms - sets real number values (e.g.: 12.56) in fixed format (the javascript base of operations format) html form input fields (but displays/edits them according browser locale, user sees formatted numbers).

grails on other hand expects input fields formatted according browser locale.

this results in conversion mismatch , effect grails loses decimal places when browser locale not english language , saves record incorrectly database.

i trying override value conversion in grails implementing custom valueconverter , registering in application context.

the request sent browser contains real value correctly ("12.45")

the main problem converter doesn't seem used @ all.

how register override defaut double info conversion?

the converter:

package gefc.dojo.binding import org.grails.databinding.converters.valueconverter import java.text.numberformat /** * converter allows doubles arrive */ class dojodoublevalueconverter implements valueconverter { numberformat fmt dojodoublevalueconverter() { // number format sent dojo components // english language locale decimal separator fmt = numberformat.getinstance(locale.english); // no grouping fmt.setgroupingused(false); } boolean canconvert(value) { value instanceof string } def convert(value) { number n = fmt.parse(value) homecoming n.doublevalue() } class<?> gettargettype() { homecoming double.class } }

my registration in application context (resources.groovy)

beans = { // dojo components send real values in fixed, iso format, while grails // expects them formatted according client/browser locale // need override real value conversions doubleconverter gefc.dojo.binding.dojodoublevalueconverter }

i have found solution.

the primary problem that, naming of converter beans wrong. 2 converters dealing double/double must called next (in applicationcontext):

"defaultgrailsdoubleconverter" (for double) "defaultgrailsjava.lang.doubleconverter" (for double)

this confusing since "defaultdateconverter" named in much more simple way , thought double converter naming consistent that.

secondary problem if want override these plugin (as opposed application project), must registration yourgrailsplugin.dowithspring() since resources.groovy not packaged plugin. if want override application project itself, placing them in resources.groovy fine.

you may want ensure registration happens after databinding plugin has been initialized, otherwise plugin may initialized first , databinding plugin overwrites converter registration defaults. may done announcing soft dependency on databinding plugin yourgrailsplugin.groovy:

def loadafter = ['databinding']

javascript grails groovy dojo

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -