2014-02-06 64 views
5

我有一個對象calendar類型AppointmentCalendar。在一個名爲calendar.jsp的jsp中,我稱之爲calendar的屬性爲calendar.day。但我得到一個錯誤說:春季應用程序沒有找到對象的屬性

org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 9): Field or property 'day' cannot be found on object of type 

任何人都可以告訴我如何解決這個問題嗎?

這裏是calendar.jsp的一部分指的是day屬性:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> 
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %> 
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>Insert title here</title> 
</head> 
<body> 
    <div id="appointmentDay" class="prepend-6 span-4 alt"> 
     <spring:eval expression="calendar.day" /> 
    </div> 
    <div id="appointmentNavigation" class="span-3 append-11 last alt"> 
     <c:url var="previousLink" value="/calendar"> 
      <c:param name="day" value="${calendar.previousDay}" /> 
     </c:url> 
     <a href="${previousLink}">Previous</a> 
     <c:url var="nextLink" value="/calendar"> 
      <c:param name="day" value="${calendar.nextDay}" /> 
     </c:url> 
     <a href="${nextLink}">Next</a> 
    </div> 
    <div id="dayPicker" class="span-6"></div> 
    ... other irrelevant code 
</body> 
</html> 

這裏是管理/calendar URL模式的EncounterController部分:

@RequestMapping("/calendar") 
public String showCalendar(Model model) { 
    LocalDate today = new LocalDate(); 
    System.out.println("------------------------ in controller, day of month is: "+today.getDayOfMonth()); 
    AppointmentCalendar calendar = new AppointmentCalendar(today); // Or whatever you do to create it 
    model.addAttribute("calendar", calendar); 
    return "appointments/calendar"; 
} 

這裏是AppointmentCalendar:

import java.util.ArrayList; 
import java.util.Date; 
import java.util.List; 
import org.joda.time.LocalDate; 
import org.joda.time.LocalTime; 
import org.springframework.format.annotation.DateTimeFormat; 

public class AppointmentCalendar { 
    @DateTimeFormat(style="F-") 
    private LocalDate day; 

    private List<Provider> providers; 

    private List<Encounter> encounters; 

    public AppointmentCalendar(LocalDate day) { 
     this.day = day; 
     System.out.println(":::::::::::::::::::::::::: in AppointmentCalendar constructor, dayOfMonth is: "+day.getDayOfMonth()); 
    } 

    public void setProviders(List<Provider> doctors) { 
     this.providers = doctors; 
     encounters = new ArrayList<Encounter>(); 
     for (int i = 0; i < 9; i++) {encounters.add(null);} 
    } 

    public void addEncounter(Encounter appointment) { 
     int blockIndex = appointment.getDateTime().getHourOfDay() - 8; 
     encounters.add(appointment); 
    } 

    public Long getDayMillis() { 
     return day.toDateTimeAtStartOfDay().getMillis(); 
    } 

    public List<LocalTime> getBlocks() { 
     List<LocalTime> blocks = new ArrayList<LocalTime>(9); 
     LocalTime time = new LocalTime(8, 0); 
     for (int i = 0; i < 9; i++) { 
      blocks.add(time); 
      time = time.plusMinutes(60); 
     } 
     return blocks; 
    } 

    public Long getBlockMillis(LocalTime block) {return day.toDateTime(block).getMillis();} 

    public Date getStartOfDay() {return day.toDateTime(getBlocks().get(0)).toDate();} 

    public Date getEndOfDay() {return day.toDateTime(getBlocks().get(8)).plusMillis(60).toDate();} 

    // resource links 

    public LocalDate getPreviousDay() {return day.minusDays(1);} 

    public LocalDate getNextDay() {return day.plusDays(1);} 

    // internal 

    private List<Encounter> createEncounterList(int size) { 
     List<Encounter> appointments = new ArrayList<Encounter>(size); 
     for (int i = 0; i < size; i++) {appointments.add(null);} 
     return appointments; 
    } 
} 

這裏是完整的堆棧跟蹤。請注意,在一開始,他們system.out.println()輸出顯示的方法是正確的順序射擊,並沒有爲day屬性的值:

------------------------ in controller, day of month is: 6 
:::::::::::::::::::::::::: in AppointmentCalendar constructor, dayOfMonth is: 6 
Feb 6, 2014 1:34:21 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar 
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 
Feb 6, 2014 1:34:22 PM org.apache.catalina.core.ApplicationDispatcher invoke 
SEVERE: Servlet.service() for servlet jsp threw exception 
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 9): Field or property 'day' cannot be found on object of type 'org.springframework.samples.knowledgemanager.model.AppointmentCalendar' 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:216) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346) 
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82) 
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) 
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:98) 
    at org.springframework.web.servlet.tags.EvalTag.doEndTag(EvalTag.java:126) 
    at org.apache.jsp.WEB_002dINF.jsp.appointments.calendar_jsp._jspx_meth_spring_005feval_005f0(calendar_jsp.java:217) 
    at org.apache.jsp.WEB_002dINF.jsp.appointments.calendar_jsp._jspService(calendar_jsp.java:114) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263) 
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208) 
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:73) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter.doFilter(DatatablesFilter.java:71) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 
Feb 6, 2014 1:34:22 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [KnowledgeManager] in context with path [/KnowledgeManager] threw exception [org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 9): Field or property 'day' cannot be found on object of type 'org.springframework.samples.knowledgemanager.model.AppointmentCalendar'] with root cause 
org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 9): Field or property 'day' cannot be found on object of type 'org.springframework.samples.knowledgemanager.model.AppointmentCalendar' 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:216) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:85) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:43) 
    at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:346) 
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82) 
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102) 
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:98) 
    at org.springframework.web.servlet.tags.EvalTag.doEndTag(EvalTag.java:126) 
    at org.apache.jsp.WEB_002dINF.jsp.appointments.calendar_jsp._jspx_meth_spring_005feval_005f0(calendar_jsp.java:217) 
    at org.apache.jsp.WEB_002dINF.jsp.appointments.calendar_jsp._jspService(calendar_jsp.java:114) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339) 
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238) 
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263) 
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208) 
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992) 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939) 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936) 
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) 
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:73) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at com.github.dandelion.datatables.extras.servlet2.filter.DatatablesFilter.doFilter(DatatablesFilter.java:71) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
    at java.lang.Thread.run(Thread.java:662) 

回答

6

您應該添加一個公共getDay()方法AppointmentCalendar
Spring需要這個獲取值來獲取day的值。

一般在使用Spring管理的beans/classes時
總是添加相應的getter和setter方法。

+0

+1,謝謝。 – CodeMed

+0

獲取日曆功能運行後,我發現我的病人管理功能無法運行,當我點擊鏈接在瀏覽器中加載它時。我想知道新問題是否與日曆代碼的設置有關。你介意看看它並試圖解決它嗎?這裏是新問題的鏈接:http://stackoverflow.com/questions/21691629/hibernate-could-not-deserialize – CodeMed