是否可以覆盖变量?

时间:2019-07-31 19:52:06

标签: jsp struts2 jstl overwrite

我正在尝试根据其ID创建到对象的链接。为此,我创建了ID列表,将其与属性ID进行比较。

我尝试将属性ID添加到变量中,然后进行比较,但是在foreach中,变量始终显示为相同的值。

                <s:if test="%{#attr.documentRow.buyRequest != null }">
                    <c:forEach items="${liveBuyRequestsId}" var="item">
                        <c:set var="liveBuyId" value="${attr.documentRow.buyRequest.id}"/>
                        <s:if test="%{attr.documentRow.buyRequest.id eq item}">
                            <s:url var="buyRequestUrl" action="buy-request-view-view" includeParams="none">
                                <s:param name="buyRequestId">${attr.documentRow.buyRequest.id}</s:param>
                                <s:param name="previousAction">${attr.buyRequestPreviousAction}</s:param>
                            </s:url>
                        </s:if>
                            <s:url var="buyRequestUrl" action="buy-request-view-history" includeParams="none">
                                <s:param name="buyRequestId">${attr.documentRow.buyRequest.id}</s:param>
                                <s:param name="changeId">${attr.documentRow.buyRequest.changeId}</s:param>
                                <s:param name="previousAction">${attr.buyRequestPreviousAction}</s:param>
                            </s:url>
                        <s:a href="%{buyRequestUrl}">
                            ${liveBuyRequestsId} (${item} by ${attr.documentRow.buyRequest.domainHolder})
                        </s:a>
                    </c:forEach>
                </s:if>
            </display:column>

我希望它基于这些语句创建url,但是变量“ liveBuyId”始终具有与

匹配的第一条记录的值。

attr.documentRow.buyRequest!=空

1 个答案:

答案 0 :(得分:0)

使用item,它是当前/最后一个值

<c:set var="liveBuyId" value="${item}"/>