1

再会。我有一个 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 中创建下拉框,以及如何为每一行选择当前值?

4

1 回答 1

2

试试这个:

<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>
于 2013-03-13T13:58:59.457 回答