没有此类属性:类的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity [英] No such property: propertyName for class: org.grails.orm.hibernate.cfg.HibernatePersistentEntity

查看:45
本文介绍了没有此类属性:类的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是grails的新手,我想在index.gsp中设置f:table的样式,我创建了一个文件_table.gsp,执行此操作时出现此错误:没有此类属性:类的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity

im new to grails, and i want to style my f:table in the index.gsp, i created a file _table.gsp, when i execute i get this error : No such property: propertyName for class: 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

i searched every where with no solution, im using grails 3.3.4, groovy 2.4.14, JVM 1.8.0_161

推荐答案

有相同的问题,这是我的解决方法:

had the same problem here's my solution:

    <%@ 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库以自然格式显示名称.

I had to import the grails.util.GrailsNameUtils library to display the name in natural format.

这篇关于没有此类属性:类的propertyName:org.grails.orm.hibernate.cfg.HibernatePersistentEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆