Update Drop Down value in Grails with <g: submitToRemote>

I just entered the Grails Arena.

I have a requirement when I want to put one snapshot and one button on one page, and by clicking on the button, only those 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)
}

Thus, in the above scenario, it sets the values ​​in devices perfectly, but from the viewpoint side, in the drop-down list, m becomes a whole connType page, and not just the list values ​​that are in the controller device variable.

Any help would be greatly appreciated.

+3
source share
1

, / , HTML. .

def getDeviceOptions = {

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

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

...

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

g:submitToRemote select.

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

.

+3

Source: https://habr.com/ru/post/1763540/


All Articles