form:spring mvc portlet中的选择项目问题

发布于 2024-10-10 19:00:41 字数 1002 浏览 0 评论 0原文

我有一组下拉控件,我想用自定义标签库来渲染它们。以下是标签库的代码:

<spring:bind path="${path}">
<c:choose>
    <c:when test="${readOnly}">
        <span class="readOnly">${status.value}</span>
    </c:when>
    <c:otherwise>
        <form:select path="${path }" itemLabel="${label }" itemValue="${value }" items="${itemList}">
        </form:select>
    </c:otherwise>
</c:choose>

这是我在 JSP 文件中编写的代码:

<tag:conditionalListControl path="model.selectedCountry"
        readOnly="false" label="name" value="id"
        listItems="model.countryList" className="simple" />

执行后,配对返回以下错误:

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

但是如果我将 items="${itemList}" 更改为 items="$ {model.countryList}" 这是我想要显示的列表,它工作正常,没有任何问题,并且还绑定到表单提交时所需的变量。

但我不想对标签库中的任何变量进行硬编码。 有什么建议吗???

I have a set of drop-down control which I want to render with my custom tag library. The following is the code of the tag lib:

<spring:bind path="${path}">
<c:choose>
    <c:when test="${readOnly}">
        <span class="readOnly">${status.value}</span>
    </c:when>
    <c:otherwise>
        <form:select path="${path }" itemLabel="${label }" itemValue="${value }" items="${itemList}">
        </form:select>
    </c:otherwise>
</c:choose>

And this is the code I have written in the JSP file:

<tag:conditionalListControl path="model.selectedCountry"
        readOnly="false" label="name" value="id"
        listItems="model.countryList" className="simple" />

Upon execution the paring returns the following error:

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

But if i change the items="${itemList}" to items="${model.countryList}" which is the list I want to display, it works fine without any problem and also bind to required variables on form submit.

But i don't want to hard code any variables in the tag lib.
Any suggestions???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾忌 2024-10-17 19:00:41

通过以下更改,问题消失了

Contact.jsp

<tag:conditionalListControl path="model.selectedQualification"
        readOnly="false" label="name" value="id"
        listItems="${model.qualificationList}" className="simple" />

conditionalListControl.tag

<%@ attribute name="listItems" required="true" type="java.util.List" %>

With following changes the problem is gone

Contact.jsp

<tag:conditionalListControl path="model.selectedQualification"
        readOnly="false" label="name" value="id"
        listItems="${model.qualificationList}" className="simple" />

conditionalListControl.tag

<%@ attribute name="listItems" required="true" type="java.util.List" %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文