当我运行grails app时,我无法查看以下所有字段,视图页面上未显示“Cost”字段,字段显示在添加页面上。如果我删除“名称”字段,则显示“费用”字段。是否存在我不知道的字段限制?
package racetrack
class Race {
String name
Date startDate
String city
String state
BigDecimal distance
BigDecimal cost
Integer maxRunners = 100000
static constraints = {
name()
startDate()
city()
state()
distance()
cost()
maxRunners()
}
}
List.gsp -
<%@ page import="racetrack.Race" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="layout" content="main" />
<g:set var="entityName" value="${message(code: 'race.label', default: 'Race')}" />
<title><g:message code="default.list.label" args="[entityName]" /></title>
</head>
<body>
<div class="nav">
<span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
<span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
</div>
<div class="body">
<h1><g:message code="default.list.label" args="[entityName]" /></h1>
<g:if test="${flash.message}">
<div class="message">${flash.message}</div>
</g:if>
<div class="list">
<table>
<thead>
<tr>
<g:sortableColumn property="id" title="${message(code: 'race.id.label', default: 'Id')}" />
<g:sortableColumn property="name" title="${message(code: 'race.name.label', default: 'Name')}" />
<g:sortableColumn property="startDate" title="${message(code: 'race.startDate.label', default: 'Start Date')}" />
<g:sortableColumn property="city" title="${message(code: 'race.city.label', default: 'City')}" />
<g:sortableColumn property="state" title="${message(code: 'race.state.label', default: 'State')}" />
<g:sortableColumn property="distance" title="${message(code: 'race.distance.label', default: 'Distance')}" />
</tr>
</thead>
<tbody>
<g:each in="${raceInstanceList}" status="i" var="raceInstance">
<tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
<td><g:link action="show" id="${raceInstance.id}">${fieldValue(bean: raceInstance, field: "id")}</g:link></td>
<td>${fieldValue(bean: raceInstance, field: "name")}</td>
<td><g:formatDate date="${raceInstance.startDate}" /></td>
<td>${fieldValue(bean: raceInstance, field: "city")}</td>
<td>${fieldValue(bean: raceInstance, field: "state")}</td>
<td>${fieldValue(bean: raceInstance, field: "distance")}</td>
</tr>
</g:each>
</tbody>
</table>
</div>
<div class="paginateButtons">
<g:paginate total="${raceInstanceTotal}" />
</div>
</div>
</body>
</html>
答案 0 :(得分:3)
假设您指的是脚手架list
视图,脚手架只会渲染六个字段。
基本逻辑(来自src/templates/scaffolding/list.gsp
)是:
props.eachWithIndex { p, i ->
if(i == 0 {
// render the field as a link to the show view
} else if(i < 6) {
// render the field value
}
}
请注意,属性列表包含id
。由于您在约束中定义了六个字段,因此最后一个字段未显示(仅限id +前五个)。
修改强>
要“修复”这个,你有一些选择:
更新脚手架列表视图代码:
grails install-templates
src/templates/scaffolding/list.gsp
找到上面的代码段并更改条件
请注意,这将更改所有脚手架和生成的列表视图的呈现。
生成视图并手动更新。
看起来您已经生成了视图,所以您只需要更新它。请注意,如果再次生成它,它将覆盖您的更改。