【问题标题】:JSP varStatus javax.el.PropertyNotFoundException: Property status is not found on typeJSP varStatus javax.el.PropertyNotFoundException:在类型上找不到属性状态
【发布时间】:2013-07-20 10:24:38
【问题描述】:

我在按索引从列表中获取对象时遇到问题:

我的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 嵌套器创建表,并在属性中使用两个对象:

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

【问题讨论】:

  • List findAttributes 中包含的类型是什么?向我们展示edu.demidov.dto.FormDate class 的定义。
  • 我已将其添加到问题帖子中
  • 那么,当您查看列表中的第五个 FormDate 时,您只关心其中包含的第五个 FormDescription 吗?这很奇怪。你不想要两个嵌套循环吗?
  • 先生,在我有 For(int=0; i
  • 你没有明白我的意思。您正在使用相同的索引来获取当前的 FormDate,并在此 FormDate 的描述列表中获取描述。我不认为那是你想要的。您可能希望另一个循环显示每个 FormDate 的所有描述

标签: jsp loops foreach jstl


【解决方案1】:

您似乎只想遍历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 进行迭代。

【讨论】:

  • 好吧,这完全是我的错。我没有明确问题的背景。先生,我已经有几天不能完全按照我想要的方式渲染我的桌子了。先生,我已经尝试过了,这是我尝试的第一种方法。 forEach 出现了问题,它重复了我所有的属性数据并将其添加到表中。如果我在列表中有 2 个对象,它会呈现 4,如果我有 3 个,它会呈现 6。当我在 中有 时会出现此问题。我无法阻止它。我在我的问题中举了例子。这就是为什么我选择使用按索引获取
【解决方案2】:

Java 代码行:

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

在您的情况下,它的 JSTL/EL 等效项将是:

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

[status] 使用括号表示法。

最好为嵌套的List 使用单独的forEach 循环。

<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 的信息。

【讨论】:

  • 先生。这是否与我有 javax.el.PropertyNotFoundException: Property 'javax.servlet.jsp.jstl.core.LoopTagSupport$1Status@70c8bc' not found on type edu.demidov.dto.FormDate ???
  • 我按照你说的做了。这就是为什么我非常准确地再次问你。我把状态放在括号内。
  • 对不起,试试${findAttributesVar.formDescriptionList[status].institutions.nameOfInstitution}
  • 是的先生,我已经尝试过了.. 它抛出异常:java.lang.IllegalArgumentException: javax.servlet.jsp.jstl.core.LoopTagSupport$1Status@1f36baf 先生,如果我将为每个列表使用单独的 forEach在这种情况下,我不需要使用 varStatus,但在这种情况下,我必须从属性中获取所有 FormDate 实体,并从同一个属性列表中获取所有 FormDescription 实体。问题可能在我的问题背景下。我在每个实体FormDate 里面都有另一个FormDescription 列表。这就是为什么我想按索引来收拾东西。
  • 我不明白你的问题中的编辑。请提供示例输入(即 FormDate 列表包含什么,以及每个 FormDate 中的描述列表包含什么),以及您希望作为输入的输出。跨度>
猜你喜欢
  • 2015-03-14
  • 2015-10-09
  • 2017-09-01
  • 2012-05-03
  • 2014-10-20
  • 2014-10-31
相关资源
最近更新 更多