Grails에 익숙하지 않아이 오류가 발생합니다. null 객체에 'id'속성을 가져올 수 없습니다. 추가하는 것 외에 조명기를 표시하는 웹 응용 프로그램을 만들려고합니다. 새로운 설비. 그러나, 응용 프로그램을 실행할 때 조명기를 추가하거나 조명기 추가 (add.gsp) 페이지를 표시 할 수 없습니다. 내 응용 프로그램에서 현재 사용할 수있는 클래스는 다음과 같습니다. 여기 Grails null 객체에 'id'속성을 가져올 수 없습니다.
package cricketfixturesgrailsapp
class Fixture {
Date date
String venue
// hasMany = [scores:Scores]
static hasMany = [team:Team]
static constraints = {
}
}
내 고정 컨트롤러 클래스입니다 : 여기
내 간단한 고정 장치 도메인 클래스 I 일정의 생성 및 업데이트를 처리하는 fixtureService을 만든
package cricketfixturesgrailsapp
class FixtureController {
//def index() { }
def FixtureService
def add() {
if (request.method == 'GET') {
[fixtureBean: new Fixture()]
}
else {
def fixture = FixtureService.createFixture(params.fixture?.date, params.fixture?.venue)
if (!fixture.hasErrors()) {
redirect action: 'show', id: fixture.id
return
}
[fixtureBean: fixture]
}
}
def show() {
def fixture = Fixture.get(params.id)
if (fixture) {
[fixtureBean: fixture]
}
}
def find() {
if (request.method == 'POST') {
def fixtures = Fixture.findAllByDate(params.date)
if (fixtures) {
if (fixtures.size() > 1) {
render view: 'selection', model: [fixtures: fixtures]
}
else {
redirect action: 'show', id: fixtures[0].id
}
}
else {
[message: 'fixtures.not.found']
}
}
}
}
package cricketfixturesgrailsapp
import grails.transaction.Transactional
//@Transactional
class FixtureService {
//def serviceMethod() {
Fixture createFixture(Date date, String venue)
{
def fixture = new Fixture(date: date, venue:venue)
fixture.save()
fixture
}
void updateFixture(Fixture fixture,Date date, String venue)
{
fixture.date = date
fixture.venue = venue
fixture.save()
}
Team createTeam(String teamName1, String teamName2, long fixtureId){
def team = new Team(teamName1: teamName1, teamName2: teamName2, fixture: Fixture.load(fixtureId))
team.save()
team
}
void updateTeam(String teamName1, String teamName2, long fixtureId) {
team.teamName1 = teamName1
team.teamName2 = teamName2
team.fixture = Fixture.load(fixtureId)
team.save()
}
}
양식 필드의 양식 필드는
입니다. 내가 3 개 GSP 파일, 고정물을 추가 찾기에 추가를 만들었습니다 또한 17,451,515,${label}: <span class="errors"><g:fieldError bean="${bean}" field="${field}" /></span>
<br/>
<g:textField name="${name + '.' +field}" value="${fieldValue(bean:bean, field:field)}" />
는 장소 및 비품을 보여줍니다 쇼하여 고정을 발견, 여기에 3 개 GSP 파일은 다음과 같습니다
는 GSP
추가<!--
To change this license header, choose License Headers in Project Properties.
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Add fixture</title>
</head>
<body>
<h2><g:if test="${!fixtureBean.id}">New </g:if>Fixture:</h2>
<g:form action="${ fixture.id ? 'edit' : 'add'}" id="${fixtureBean?.id}">
<table>
<tr>
<th>
<g:render template="/common/formField"
model="[name:'fixture', bean:fixtureBean, field:'date', label:'Date']" />
</th>
</tr>
<tr>
<th>
<g:render template="/common/formField"
model="[name:'fixture', bean:fixtureBean, field:'venue', label:'Venue']" />
</th>
</tr>
<tr>
<td>
<p><input type="submit" value="${ fixtureBean.id ? 'Update' : 'Add'} Fixture"/></p>
</td>
</tr>
</table>
</g:form>
</body>
</html>
</body>
</html>
find.gsp
<html>
<head>
<meta name="layout" content="main">
<title>Find fixtures</title>
</head>
<body id="find">
<h2>Find fixtures:</h2>
<g:form action="find">
<table>
<tr>
<th>
venue
<br/>
<g:textField name="venue"/>
<span class="errors"><g:message code="${message}"></g:message></span>
</th>
</tr>
<tr>
<td><p class="submit"><input type="submit" value="Find fixtures"/></p></td>
</tr>
</table>
</g:form>
<br/>
<g:link controller="Fixture" action="add">Add fixture</g:link></a>
</body>
</html>
show.gsp
,또한 내 기본 홈 페이지는 사용자가 차례로 고정이
....Error
|
2014-02-23 20:35:23,016 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /CricketFixturesGrailsApp/fixture/add
Cannot get property 'id' on null object. Stacktrace follows:
Message: Error evaluating expression [fixture.id ? 'edit' : 'add'] on line [20]: Cannot get property 'id' on null object
Line | Method
->> 20 | doCall in C:/apache-tomcat-7.0.50/webapps/CricketFixturesGrailsApp/grails-app/views/fixture/add.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by NullPointerException: Cannot get property 'id' on null object
->> 44 | doCall in C__apache_tomcat_7_0_50_webapps_CricketFixturesGrailsApp_grails_app_views_fixture_add_gsp$_run_closure2_closure8
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 47 | run in C__apache_tomcat_7_0_50_webapps_CricketFixturesGrailsApp_grails_app_views_fixture_add_gsp
| 200 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 722 | run . . . in java.lang.Thread
전체 Stactrace를 추가했습니다 – Sky
'fixtureBean.id를 사용해 보셨습니까? 'edit': 'add.gsp'에'add '라고 쓰여진 답안에 언급 된 수정 사항 이외에? @Sky – dmahapatro
감사합니다. 제안 된 변경 사항을 적용한 후에 작동합니다. – Sky