开发者

Grails error: No such property: it for class:

Below is my code. Here I am getting an error which is 'No such property: it for class: emp.EmployeeController'. I think I am doing something wrong here. Any advice??

def list ={

    def id=params.id
    def results

    String employee="SELECT empName, empDate, empNo from employee where empId='id'"     
    String referrer="SELECT  empName, empDate, empNo from referer where empId='id'"


    def employeeInstanceList = new ArrayList<Employee>()
    Sql sql = new Sql(dataSource)
    def joining=null
    joining = sql.rows( "select joining from employee_dates")


    if (joining!=null)      
    results = sql.eachRow(employee)
    employeeInstanceList=getCalculatedEmployeeData(results)
    /*{

        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee
    }*/

    else

    results = sql.rows (currentDaySql)
    employeeInstanceList=getCalculatedEmployeeData(results)
    /*{
        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee       }*/ 

    }


    [employeeInstanceList: [employeeInstanceList: employeeInstanceTotal: Employee.count()]
}


def getCalculatedImpactData(def results){
        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee       }*/
    return [employeeInstanceList: em开发者_开发问答ployeeInstanceList]
}

Thanks, Meghana


i would second leebutts answer... but just a pointer, the usage of the it keyword is usually confined to closures... so instead of doing this in java:

List l = [];
for (Iterator i = l.iterator(); i.hasNext(); ) {
  ...do something adressing List l at position i...
}

you could do this in groovy / grails:

list.each { it ->
  ...do something with each object in the list (it)...
}

but you should really read up on groovy closures at http://groovy.codehaus.org/Closures


There is so much wrong with that code, I don't know where to start...

But to avoid getting more down votes I have tried :)

I tried to copy your code into an IDE and try and work out what you are trying to achieve but couldn't.

This is as close as I could get it:

 def list = {
        def id = parmas.id
        def results

        String employee = "SELECT empName, empDate, empNo from employe"

        def employeeInstanceList 
        Sql sql = new Sql(dataSource)
        def joining = sql.rows("select joining from employee_dates")

        if (joining != null) {
            results = sql.eachRow(employee)
            employeeInstanceList = getCalculatedEmployeeData(results)
        }
        else {
            results = sql.rows(currentDaySql)
            employeeInstanceList = getCalculatedEmployeeData(results)
        }

        [employeeInstanceList: employeeInstanceList, employeeInstanceTotal: Employee.count()]
    }


    def getCalculatedImpactData(def results) {
        def employeeInstanceList = new ArrayList<Employee>()
        results.each { it ->
            def employee = new Employee()
            employee.empName = it.empName
            employee.empNo = it.empNo
            employee.empDate = it.EmpDate
            employeeInstanceList.add(employee)
        }
        return employeeInstanceList
    }

but it is still referring to a variable currentDaySql which doesn't exist and I'm not sure what you're trying to do with the 'joining' result.

You really need to read up on Groovy basics.


The block of code where the error occurs is probably:

def getCalculatedImpactData(def results){
    def employee = new Employee()
    employee.setempName it.empName
    employee.setEmpNo it.empNo
    employee.setEmpDate it.EmpDate
    employeeInstanceList.add employee
    return [employeeInstanceList: employeeInstanceList]
}

it is not defined anywhere (hint: the compilation error told you this). Like Sebastian said, it is typically used in closures; what you've defined here is a function. Presumably you wanted to use results (or something) instead of it here.

I'm assuming that some of the things in your code (e.g. comment opening/closing) weren't in there and were added between when you saw the error and when you posted the code. Otherwise you'd get other errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜