Question

basically the domain to save not respect the floating point, as it makes it to another format

i have the next domain

class Location {
    double latitude
    double longitude
    static belongsTo=[ product: Product ]   
    static constraints = {      
        latitude nullable:false, blank:false
        longitude nullable:false, blank:false       
    }
}

view:

<g:form class="form-horizontal" action="create" id="${locationInstance?.product?.id}" >
    <fieldset>
        <f:with bean="locationInstance">
            <f:field property="lat"/>
            <f:field property="lon"/>
        </f:with>
    </fieldset>
</g:form>
<button type="button" class="submit btn btn-primary">
        <i class="icon-plus"></i>
        <g:message code="default.add.label" args="[message(code: 'location.label', default:'Location')]" default="Add Map"/>
</button>

controller:

import grails.converters.JSON
class LocationController {
    def create() {
    def model = [productInstance:Product.findByIdAndUser(params.remove("id"),negoexService.currentUser)]
    def responseReturn = [success:false]
    def redirectParams = [controller:"product", action:"list"]
    if (!model.productInstance) {
        responseReturn.message = message(code: "default.not.found.message", args: [message(code: "product.label", default: "Product"), params.id])
    }else{
        redirectParams.action = "edit"
        redirectParams.id = model.productInstance.id
        params.product = model.productInstance
        params.remove("action")
        params.remove("controller")
        model.locationInstance = new Location(params)
        println params // here are showed 29.089177 and -110.961227
        println model.locationInstance.lat // out is 2.9089177E7
        println model.locationInstance.lon // out is -1.10961227E8
        if(request.method=="POST"){
            if (model.locationInstance.save(flush: true)) {
                responseReturn.success = true
                responseReturn.message = message(code: "default.created.message", args: [message(code: "location.label", default: "Location"), model.locationInstance])
            }else{
                responseReturn.errors = model.locationInstance.errors.allErrors
            }
        }
    }
    withFormat {
        html {
            if(request.xhr && !model.productInstance){
                render view:"/messageAjax", model:responseReturn
            }else{
                if(responseReturn.message){flash.message = responseReturn.message}
                if(!model.productInstance || responseReturn.success){
                    redirect redirectParams
                }else{
                    render view:"create"+(request.xhr?"Ajax":""), model:model
                }
            }
        }
        json {render responseReturn as JSON}
        js   {render responseReturn as JSON}
        xml  {render responseReturn as XML}
    }
}

to request Location save()

the params arrive like params.latitude=29.089177 and params.longitude=-110.961227 after save the values are stored like locationInstance.latitude=29089177 and locationInstance.longitude=-110961227 in the data base.

To be showed in a view appears like latitude=2.9089177E7 and longitude=-1.10961227E8

what would be the problem, i have another project with theme class and run correctly. and try changing the names of the properties and the type to float and not resolved

Thanks!

Was it helpful?

Solution

just add this in conf/spring/resources.groovy

beans = {
    localeResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) {
        defaultLocale = new Locale("es","MX")
        java.util.Locale.setDefault(defaultLocale)
    }
} 

to persist coordinates format, and that the values ​​are not changed when saving.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top