【问题标题】:Generate drop down box in JSP with SPRING使用 SPRING 在 JSP 中生成下拉框
【发布时间】:2013-03-13 13:54:03
【问题描述】:

美好的一天。 我有一个 JSP 视图和一个控制器,它为它提供了一个要填充的模型。 这是我的控制器的 JSP 方法。

@RequestMapping("/seller")
public ModelAndView seller() {
    if(isUserInRole("SELLER_ROLE"))
    {
        List<SellerStatistics> entities = sellerService.getAllStatistics().getContent();
        List<String> statuses = sellerService.getStatuses();
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("gridRows", entities);
        model.put("statuses", statuses);
        return new ModelAndView("seller",model);
    }
    return new ModelAndView("login");
}

gridRows 包含必须插入到 JSP 表中的信息。该表中的一列是“状态”。状态必须是一个下拉框才能更改此行的状态。

这是我的 JSP:

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="header.jsp" %>
<div class="container">
    <div class="row">
        <div class="span12">
            <h1>Sellers welcome</h1>

            <div class="top-menu">
                <span>Период</span><input type="text">
                <span>Период</span><input type="text">
                <span>Период</span><input type="text">
                <span>Период</span><input type="text">
                <span>Период</span><input type="text">
                <input type="button">
            </div>
            <table class="table table-bordered table-hover table-condensed">
                <thead>
                <tr>
                    <th>id</th>
                    <th>Email</th>
                    <th>Телефон</th>
                    <th>Дата регистрации</th>
                    <th>Сайт откуда первый раз пришел</th>
                    <th>Первый поисковый запрос</th>
                    <th>Оплата</th>
                    <th>Счет/Реализация/Счет фактура</th>
                    <th>Журнал посещений</th>
                    <th>Журнал коммуникаций</th>
                    <th>Статус</th>
                </tr>
                </thead>
                <c:forEach items="${gridRows}" var="cur">
                    <tr>
                        <td>${cur.id }</td>
                        <td>${cur.email }</td>
                        <td>${cur.phone}</td>
                        <td><fmt:formatDate pattern='dd.MM.yyyy HH:mm' value='${cur.registrationDate}'/></td>
                        <td><a href="${cur.referer}">${cur.referer}</a></td>
                        <td>${cur.searchQuery}</td>
                            <%--Payments--%>
                        <td>
                            <c:forEach items="${cur.payments}" var="payment">
                                <fmt:formatDate pattern='dd.MM.yyyy' value='${payment.created}'/>
                                &nbsp;&nbsp;
                                ${payment.value} рублей
                            </c:forEach>
                        </td>

                        <td>${cur.aii}</td>
                        <td>${cur.visits}&nbsp;страниц<br><a
                                href="/seller/browsing_history?id=${cur.id}">Подробно</a></td>
                        <td>
                            <c:forEach items="${cur.communicationLog}" var="communication">
                                <a href="#">${communication.time}&nbsp;&nbsp;${communication.description}</a>
                            </c:forEach>
                        </td>
                        <td>
                             <!--Status must be here-->
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </div>
</div>

如何在JSP中创建下拉框,如何为每一行选择当前值?

【问题讨论】:

    标签: java spring jsp model-view-controller


    【解决方案1】:

    试试这个:

    <select>  
        <c:forEach var="item" items="${statuses}">  
            <c:choose>
                <c:when test="${cur.status == item}">
                    <option selected>${item}</option>
                </c:when>
                <c:otherwise>
                    <option>${item}</option>
                </c:otherwise>
            </c:choose>
        </c:forEach>  
    </select>
    

    【讨论】:

    • 它必须生成下拉框,但是如何为每一行选择当前状态?我需要某种检查当前网格行的状态必须是什么。
    • 如何访问混凝土行的当前状态?我不知道Status类结构
    • 状态只是一个字符串。在 SellerStatistics 项目(代表行)中有一个字段状态(也是字符串类型)。
    猜你喜欢
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多