0

我正在尝试在 JSP 标记中完成以下操作:

选择标签

<%@ attribute name="id" required="true" %>
<%@ attribute name="path" required="true" %>
<%@ attribute name="items" required="true" %>
<%@ attribute name="itemLabel" required="false" %>
<%@ attribute name="itemValue" required="false" %>

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<form:select path="${path}" id="${id}">
    <form:options items="${items}" itemLabel="${itemLabel}" itemValue="${itemValue}"/>
</form:select>

用法:(mycollectionattribute 使用 @ModelAttribute("mycollectionattribute") 定义)

<tags:select items="${mycollectionattribute}" id="id" path="mybean.selectvalue" itemLabel="label" itemValue="id"/>

但是,我不知道如何正确地将调用页面中的项目集合映射到这个标签。EL 似乎没有被评估并作为字符串发送,导致以下错误:

javax.servlet.ServletException: Type [java.lang.String] is not valid for option items

我正在使用一个相当旧的 JSTL 版本,它与 JBoss 4.04GA 捆绑在一起,这可能是问题吗?我不确定何时准确评估 EL 表达式,例如,直接在标记中的 ${x} 不会评估,它仅适用于特殊标签。升级能解决这个问题吗?如果是这样,使用您自己的 JSTL 库而不是与 JBoss 捆绑的库有多难?

4

1 回答 1

0

解决了。

使用了不匹配的 servlet 版本(指定了 2.5,但 JBoss 4 使用 2.4),既作为依赖项又在 web.xml 中。所以EL没有像它应该的那样工作。

于 2012-03-01T12:40:39.197 回答