tags:

views:

93

answers:

1

Hello All..

I have just entered into the Grails arena.

I have a requirement where I want to put one drop down and one button on one page, and by clicking on button only that drop down values should be changed, other controls on the page should remain unchanged.

My code is as follows :

_connType.gsp

<div id="mappedDeviceDiv">
    <select id="mappedDevice" name="mappedDevice" value="" style="width:200px">
    <g:each in="${deviceList}" status="i" var="dl">
        <option value="${dl}">${dl}</option>
    </g:each>
    </select>

    <g:submitToRemote class="blackButton" update="mappedDeviceDiv"
          url="${[controller:'resource',action:'getDeviceList']}"
          value="Get Devices"/>
</div>

ResourceController.groovy

def getDeviceList = {

    println "Getting NV devices.. + Nirmal" + params
    def model = buildAccessRequestModel()

    List<NVDeviceBean> deviceList = NVUtil.getDevices(params.datasource, null);
    Collections.sort(deviceList);
    List<String> devices = []
    for(NVDeviceBean deviceBean : deviceList) {
        devices.add(deviceBean.getName())
    }
    println "list = "+devices
    model.putAt('deviceList', devices)
    render (template:'config/connType',model:model)
}

So, in above scenario, it's setting the values in the devices perfectly, but at the view side in a drop down m getting whole connType page, instead of only list values which is in devices variable of controller.

Any help would be highly appreciated..

+1  A: 

You might want to create/modify one of the controller actions to return a list of HTML options. You could even have this action render a template, too.

def getDeviceOptions = {

    def options = []
    // code that creates the option list goes here.

    render(template:'config/optionList', model: [optionList: options ])
}

And the template...

<!-- config/_optionList.gsp -->
<g:each in="${optionList}" status="i" var="dl">
    <option value="${dl}">${dl}</option>
</g:each>

Then, tell the g:submitToRemote tag to update the select object.

<g:submitToRemote class="blackButton" update="mappedDevice"
      url="${[controller:'resource',action:'getDeviceOptions']}"
      value="Get Devices"/>

That should get you started in the right direction.

Pat
This looks as good answer.
amra