Search code examples
grailsgrails-ormgrails-2.0

Why value is viewing with [] in grails view


I am calling an action by remoteFunction for showing some value in some field.The value is viewing but with in []. I have no idea why it is behaving like this. Can anyone please help me on this please ? I am using grails 2.1.0. here are my attempts below :

my remoteFunction >>

<g:remoteFunction action="setValueForDetails"  params="'procurementMasterId='+procurementMasterId" update="changedValue"/>

my action in controller >>

def setValueForDetails(){
    def otmIFQDetailsByProcurementMaster
    if(params.procurementMasterId != null && params.procurementMasterId != "" && params.procurementMasterId != "null"){
       otmIFQDetailsByProcurementMaster = commonService.getOtmIFQDetailsValueByProcurementMaster(Long.parseLong(params.procurementMasterId))
    }
    render (template: 'ifqDetails', model: [otmIFQDetailsByProcurementMaster: otmIFQDetailsByProcurementMaster])
}

my field where I want to set the value in template >>

<g:textField id="PROCUREMENT_TYPE" name="PROCUREMENT_TYPE.id" readonly="" value="${otmIFQDetailsByProcurementMaster?.PROCUREMENT_TYPE}" class="form-control" />

Solution

  • I guess the 'PROCUREMENT_TYPE" is an Array of enums due to spelling, and displaying. So if You want to 'print' value without square brackets, You should change value to (if You want only first result):

    value="${otmIFQDetailsByProcurementMaster?.PROCUREMENT_TYPE[0]}"
    

    or if You want to should more than one element from list:

    value="${otmIFQDetailsByProcurementMaster?.PROCUREMENT_TYPE.toString().replace('[', '').replace(']', '')}"
    

    or simply iterate through the elements of PROCUREMENT_TYPE and show as many textfield as many PROCUREMENT_TYPE values You have.