2013-07-21 40 views
1

我在通過指數從列表中選擇獲取對象發現問題:JSP varStatus javax.el.PropertyNotFoundException:物業狀態不是類型

我的jsp:

<c:choose>  

       <c:when test="${empty findAttributes}"> 

        <h1 align="center">Attributes are empty</h1> 

       </c:when> 

       <c:otherwise> 


        <table align="center" border="1" id="resultTable"> 


          <c:forEach items="${findAttributes}" var="findAttributesVar" varStatus="status"> 

            <tr>  

            <td align="center">${findAttributesVar.status.index.formDescriptionList.status.status.institutions.nameOfInstitution}</td> 

            <td align="center">${findAttributesVar.status.index.formDescriptionList.status.status.institutionType.typeOfInstitution}</td> 

<td align="center">${findAttributesVar.status.index.formDescriptionList.daySchedule}</td> 

            <td align="center">${findAttributesVar.status.index.formDescriptionList.workScheduale}</td> 

            </tr> 

          </c:forEach>                          

        </table> 

       </c:otherwise> 

      </c:choose> 

我取作爲屬性列表findAttributes並試圖讓在jsp頁面通過索引對象,類似於像java代碼:

attributesList.get(i).getFormDescriptionList().get(i).getInstitutions().getNameOfInstitution()); 
attributesList.get(i).getFormDescriptionList().get(i).getInstitutionType().getTypeOfInstitution(); 
attributesList.get(i).getParticularDate().toString()); 
attributesList.get(i).getFormDescriptionList().get(i).getDaySchedule()); 
attributesList.get(i).getFormDescriptionList().get(i).getWorkScheduale()); 

我的堆棧跟蹤錯誤:

Jul 26, 2013 4:57:18 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [appServlet] in context with path [/web] threw exception [An exception occurred processing JSP page /WEB-INF/views/search.jsp at line 141 

138:        <tr>  
139:         
140:        <td align="center">${findAttributesVar.particularDate}</td> 
141:        <td align="center">${findAttributesVar.status.index.formDescriptionList.daySchedule}</td> 
142:        <td align="center">${findAttributesVar.status.index.formDescriptionList.workScheduale}</td> 
143:        <td align="center">${findAttributesVar.status.index.formDescriptionList.rotation}</td> 
144:        <td align="center">${findAttributesVar.status.index.formDescriptionList.numberOfKids}</td> 


Stacktrace:] with root cause 
javax.el.PropertyNotFoundException: Property 'status' not found on type edu.demidov.dto.FormDate 
    at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:223) 
    at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:200) 
    at javax.el.BeanELResolver.property(BeanELResolver.java:311) 
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:85) 
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67) 
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169) 
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) 
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:985) 
    at org.apache.jsp.WEB_002dINF.views.search_jsp._jspx_meth_c_005fforEach_005f3(search_jsp.java:1157) 
    at org.apache.jsp.WEB_002dINF.views.search_jsp._jspx_meth_c_005fotherwise_005f0(search_jsp.java:790) 
    at org.apache.jsp.WEB_002dINF.views.search_jsp._jspx_meth_c_005fchoose_005f0(search_jsp.java:639) 
    at org.apache.jsp.WEB_002dINF.views.search_jsp._jspService(search_jsp.java:222) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329) 
    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:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    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:240) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 

我FormDate實體:

包edu.demidov.dto;

@Entity 
@Table(name="FORM_DATE") 
public class FormDate implements Serializable{ 


    private static final long serialVersionUID = -6727012506326164775L; 


    private int dateId; 

     @Id 
     @GeneratedValue(strategy= IDENTITY) 
     @Column(name="DATE_ID") 
     public int getDateId() { 
      return dateId; 
     } 
     public void setDateId(int dateId) { 
      this.dateId = dateId; 
     } 


    private int version; 

     @Version 
     @Column(name="VERSION") 
     public int getVersion() { 
      return version; 
     } 
     public void setVersion(int version) { 
      this.version = version; 
     } 


    private Date particularDate; 

     @Column(name="PARTICULAR_DATE") 
     @DateTimeFormat(pattern="yyyy-MM-dd") 
     @Temporal(TemporalType.DATE) 
     public Date getParticularDate() { 
      return particularDate; 
     } 
     public void setParticularDate(Date particularDate) { 
      this.particularDate = particularDate; 
     } 


    private List<FormDescription> formDescriptionList = new ArrayList<FormDescription>(); 

     @OneToMany(mappedBy="formDate") 
     @Cascade(CascadeType.ALL) 
     public List<FormDescription> getFormDescriptionList() { 
      return formDescriptionList; 
     } 
     public void setFormDescriptionList(List<FormDescription> formDescriptionList) { 
      this.formDescriptionList = formDescriptionList; 
     } 

} 

它是如何創建表與c:forEachc:forEach巢與屬性的兩個對象:

  -=TABLE=- 
|header1|header2|header3| 
------------------------- 
|value1| Value1 |value1 | 
------------------------- 
|value2| Value2 |value2 | 
------------------------- 
|value1| Value1 |value1 | 
------------------------- 
|value2| Value2 |value2 | 
+0

'List findAttributes'中包含的是什麼類型?向我們展示'edu.demidov.dto.FormDate'類的定義。 – NINCOMPOOP

+0

我將它添加到問題文章 –

+0

因此,當您查看列表中的第五個FormDate時,您只關心它包含的第五個FormDescription?這很奇怪。難道你不想要兩個嵌套循環嗎? –

回答

0

的Java代碼的行:

attributesList.get(i).getFormDescriptionList().get(i). 
getInstitutions().getNameOfInstitution()); 

其JSTL/EL等同於你的情況將是:

${findAttributes[status].formDescriptionList[status].institutions.nameOfInstitution} 

使用[status]的括號表示法。

更好地使用單獨的forEach循環嵌套List

<c:forEach items="${findAttributes}" var="findAttributesVar"> 
    <c:forEach items=${findAttributesVar.formDescriptionList} var="formDescription"> 
     Value : ${formDescription.institutions.nameOfInstitution} 
    </c:forEach> 
</c:forEach> 

記住你這裏指的應該具有公共getter方法按照這個Java bean規範所有的bean類。和命名約定。 Read this瞭解如何使用EL的更多信息。

+0

先生。這是關於「公共getter方法根據Java bean規範和命名約定」,我有javax.el.PropertyNotFoundException:屬性'[email protected]'找不到類型edu.demidov.dto.FormDate ??? –

+0

我做了你說的話。這就是爲什麼我很準確地再次問你。我把狀態放在括號內。 –

+0

對不起,您可以使用'$ {find {{findAttributesVar.formDescriptionList [status] .institutions.nameOfInstitution}'! – NINCOMPOOP

0

看來你只是想遍歷FormDate實例列表,並顯示列表中每個FormDate的每個FormDescription。所以,你需要的第一環:

$ {} formDate.particularDate這裏 應在當前formDate的FormDescription的列表中顯示

你不需要varStatus這個循環,就像在Java中,您只需要

for (FormDate formDate : findAttributes) { 
    System.out.println(formDate.getParticularDate()); 
    System.out.println("here should the list of FormDescription of the current formDate be displayed"); 
} 

不需要任何當前迭代的索引。

要顯示FormDescriptions的名單,你需要另一個循環:

for (FormDate formDate : findAttributes) { 
    System.out.println(formDate.getParticularDate()); 
    for (FormDescription description : formDate.getFormDescriptionList()) { 
     System.out.println(" " + description.getDaySchedule()); 
     System.out.println(" " + description.getWorkSchedule()); 
    } 
} 

注意再次,你不需要任何索引。在JSP中,它看起來像

<c:forEach var="formDate" items="${findAttributes}"> 
<tr> 
    <td>${formDate.particularDate}</td> 
    <td> 
     <ul> 
      <c:forEach var="description" items="${formDate.formDescriptionList}> 
       <li> 
        ${description.daySchedule} - ${description.workSchedule} 
       </li> 
      </c:forEach>    
     </ul> 
    </td> 
</tr> 

當然,佈局是由你。但是您應該瞭解如何使用c:forEach進行迭代。

+0

好吧,這完全是我的錯。我沒有提出明確的問題背景。主席先生,我已經有幾天不能完全讓我的桌子按我想要的方式呈現。主席先生,我已經嘗試過了,這是我第一次嘗試做到這一點。問題出現在forEach中,它重複了我所有的屬性數據並將其添加到表中。如果我在列表中有2個對象,它會渲染4,如果我有3渲染6.這個問題發生在裏面。我不能阻止它。我在我的問題中列舉了一些例子這就是爲什麼我選擇使用索引獲取 –

相關問題