JSP varStatus javax.el.PropertyNotFoundException:在类型上找不到属性状态

时间:2013-07-21 17:10:01

标签: jsp loops foreach jstl

我遇到了按索引从List获取对象的问题:

我的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:forEach中使用c:forEach nester创建具有属性中的两个对象的表:

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

2 个答案:

答案 0 :(得分: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>

请记住,您在此处引用的所有bean类都应该具有符合Java bean规范的公共getter方法。和命名约定。 Read this了解有关如何使用EL的更多信息。

答案 1 :(得分: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迭代。