Quantcast

Parent and Child mapping list check in groovy and grails

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Parent and Child mapping list check in groovy and grails

debobrota
My objective is to ensure parent child list check using groovy and grails

Step1: write ajax code in your gsp view page

<html>
    <head>
        <meta name="layout" content="main">
        <g:set var="entityName" value="${message(code: 'WFLayer.label', default: 'WFLayer')}" />
        <g:javascript library="prototype"/> 
             
       
        <g:javascript>
            document.observe('dom:loaded', function() {
                $("master").observe("change", respondToSelect);
            });

           
            function respondToSelect(event)
            {
               new Ajax.Updater("sub", "/ADHRPAY/WFLayer/getDate",
                                {
                                method:'get', parameters:
                                {
                                selectedValue : $F("master")
                                }, onSuccess: function(transport)
                                {
                                   
                                     setTimeout(initializeSub,1000);  
                                }
                                }
                                );
                                                 
            }                                                                                  
        </g:javascript>
       
        <title><g:message code="default.create.label" args="[entityName]" /></title>           
    </head>


in above code /ADHRPAY/WFLayer/getDate. is called /ProjectName/ControllerName/method

Step2: write method code in your groovy class

def getDate() {
               def result
        def sqlConnect = new Sql(dataSource)
        if(params.selectedValue=='Department'){
            result = sqlConnect.rows("select department_name as name from departments")
        }
        else if(params.selectedValue=='Section'){
            result = sqlConnect.rows("select section_name as name from sections")
        }
        else if(params.selectedValue == "Employee"){
            result = sqlConnect.rows("select concat(first_name,' ',last_name) as name from employees")
        }
        render(template:'getListValue',model:[selectResult:result])
       
    }
   

Step3: write template code in your template gsp view

<g:select name="sub" value="" from="${selectResult.name}"></g:select>

Step4: Finally change your gsp page from which you are sending value to your controller using Ajax support.

<div class="fieldcontain ${hasErrors(bean: WFLayerInstance, field: 'layerType', 'error')} ">
    <label for="layerType">
        <g:message code="WFLayer.layerType.label" default="Layer Type" />
       
    </label>
    <%-- <g:select id="master" name="master" from="${WFLayerInstance.constraints.layerType.inList}" value="${WFLayerInstance?.layerType}" valueMessagePrefix="WFLayer.layerType" noSelection="['': '']"/> --%>
    <g:select id="master" from="${WFLayerInstance.constraints.layerType.inList}" name="master" />
</div>

<div class="fieldcontain ${hasErrors(bean: WFLayerInstance, field: 'layerId', 'error')} required">
    <label for="layerId">
        <g:message code="WFLayer.layerId.label" default="Layer Name" />
    </label>
    <g:select id="sub" name="sub" from="" value="${WFLayerInstance.layerId}"/>
</div>



Best way to keep your all GSP file in same folder.
Step5: Now run your application and then you will get below output(once your select layer type then layer name will be displayed).
Loading...