没有这样的属性:class的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity

时间:2018-05-07 09:23:05

标签: grails gsp

我是grails的新手,我想在index.gsp中设置我的f:table样式,我创建了一个文件_table.gsp,当我执行时我得到了这个错误: 没有这样的属性:class的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity

index.gsp中

<!DOCTYPE html>
<html>
<head>
<meta name="layout" content="main" />
<g:set var="entityName" value="${message(code: 'user.label', default: 'User')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
<div class="breadcrumbs">
<div class="col-sm-3">
<a href="#list-user"><g:message code="default.link.skip.label" default="Skip to content&hellip;"/></a>
</div>
<div class="col-sm-3">
<a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a>
</div>
<div class="col-sm-3">
<g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link>
</div>
</div>
<br>
<br>
<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-header">
<strong class="card-title"><g:message code="default.list.label" args="[entityName]" /></strong>
</div>
<div class="card-body">
<div id="pay-invoice">
<div class="card-body">
<div id="list-user" class="content scaffold-list" role="main">
<g:if test="${flash.message}">
<div class="message" role="status">${flash.message}</div>
</g:if>
<f:table collection="${userList}"/>    
<div class="pagination">
<g:paginate total="${userCount ?: 0}" />
</div>
</div>
</div>
</div>
</div>
</div> <!-- .card -->
</div>
</div>
</body>
</html>

_table.gsp

<table class="table stripped-table">
<thead>
<tr>
<g:each in="${domainClass}" var="p" status="i">
<g:set var="propTitle">${domainClass.propertyName}.${p.name}.label</g:set>
<g:sortableColumn property="${p.name}" title="${message(code: propTitle, default: p.naturalName)}" />
</g:each>
</tr>
</thead>
<tbody>
<g:each in="${collection}" var="bean" status="i">
<tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
<g:each in="${domainProperties}" var="p" status="j">
<g:if test="${j==0}">
<td><g:link method="GET" resource="${bean}"><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" /></g:link></td>
</g:if>
<g:else>
<td><f:display bean="${bean}" property="${p.name}"  displayStyle="${displayStyle?:'table'}" /></td>
</g:else>
</g:each>
</tr>
</g:each>
</tbody>
</table>

User.groovy

class User {

transient securiteService

String username
String password
String nom
String prenom
String email
String tel

static hasMany = [roles : Role]

static constraints = {
    username blank: false, unique: true
    password blank: false
    nom nullable: true
    prenom nullable: true
    email email:true, nullable:true
    tel nullable:true, maxSize:20,  matches:/[\+]{0,1}[0-9\s]{3,15}/
}

static mapping = {
    password column: '`password`'
    sort nom: "asc"
    affectations sort : "dateAffectation", order:"desc"
    intervention sort : "responsable", order:"desc"
}
}

usercontroller.groovy

package mylicence

import grails.validation.ValidationException
import static org.springframework.http.HttpStatus.*
import java.security.MessageDigest

class UserController {

UserService userService

static allowedMethods = [save: "POST", update: "PUT", delete: "DELETE"]

def index(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    respond userService.list(params), model:[userCount: userService.count()]
}

def show(Long id) {
    respond userService.get(id)
}

def create() {
    respond new User(username: params.username, password: params.password, nom: params.nom, prenom: params.prenom, email: params.email, tel: params.tel)
}

def save(User user) {
    if (user == null) {
        notFound()
        return
    }

    try {
        userService.save(user)
    } catch (ValidationException e) {
        respond user.errors, view:'create'
        return
    }

    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.created.message', args: [message(code: 'user.label', default: 'User'), user.id])
            redirect user
        }
        '*' { respond user, [status: CREATED] }
    }
}

def edit(Long id) {
    respond userService.get(id)
}

def update(User user) {
    if (user == null) {
        notFound()
        return
    }

    try {
        userService.save(user)
    } catch (ValidationException e) {
        respond user.errors, view:'edit'
        return
    }

    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.updated.message', args: [message(code: 'user.label', default: 'User'), user.id])
            redirect user
        }
        '*'{ respond user, [status: OK] }
    }
}

def delete(Long id) {
    if (id == null) {
        notFound()
        return
    }

    userService.delete(id)

    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.deleted.message', args: [message(code: 'user.label', default: 'User'), id])
            redirect action:"index", method:"GET"
        }
        '*'{ render status: NO_CONTENT }
    }
}

protected void notFound() {
    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'user.label', default: 'User'), params.id])
            redirect action: "index", method: "GET"
        }
        '*'{ render status: NOT_FOUND }
    }
}

def login() {

}

def handlelogin = {
    def hashPassd = params.password
    // Find the username
    def user = User.findByUsernameAndPassword(params.username, hashPassd)
    if (!user) {
        flash.message = "User not found for userName: ${params.username}"
        redirect(action:'login')
        return
    } else {
        session.user = user
        redirect(controller:'user')
    }
}

def logout = {
    //log.info 'logout'
    if(session.user) {
        session.user = null
        session.invalidate()
        redirect(controller:'user', action: 'login')
    }
    else {
        redirect(controller:'user', action: 'login')
    }
}

}

我搜索了所有没有解决方案的地方,使用grails 3.3.4,groovy 2.4.14,JVM 1.8.0_161

1 个答案:

答案 0 :(得分:2)

在这里有同样的问题我的解决方案:

    <%@ page import="grails.util.GrailsNameUtils" %>
<table >
    <thead>
    <tr>

        <g:each in="${domainProperties}" var="p" status="i">
            <g:set var="propTitle">${domainClass.decapitalizedName}.${p.name}.label</g:set>
            <g:sortableColumn property="${p.name}" title="${message(code: propTitle, default: grails.util.GrailsNameUtils.getNaturalName(p.name))}" />
        </g:each>
    </tr>
    </thead>
    <tbody>
    <g:each in="${collection}" var="bean" status="i">
        <tr class="${(i % 2) == 0 ? 'even' : 'odd'}">
            <g:each in="${domainProperties}" var="p" status="j">
                <g:if test="${j==0}">
                    <td><g:link method="GET" resource="${bean}"><f:display bean="${bean}" property="${p.name}" displayStyle="${displayStyle?:'table'}" /></g:link></td>
                </g:if>
                <g:else>
                    <td><f:display bean="${bean}" property="${p.name}"  displayStyle="${displayStyle?:'table'}" /></td>
                </g:else>
            </g:each>
        </tr>
    </g:each>
    </tbody>
</table>

我必须导入grails.util.GrailsNameUtils库以自然格式显示名称。