0

I have the following jsp

           ...  
           <table id="table" class="sortable">
                        <thead>
                        <tr>
                            <td class="head">Дата Запроса</td>
                            <td class="head">Сумма Запроса</td>
                            <td class="head">Баланс Владельца</td>
                            <td class="head">Статус Запроса</td>
                            <td class="head">Email</td>
                            <td class="head">-----</td>
                        </tr>
                        </thead>

                        <tbody>
                        <c:forEach var="event" items="${events}">
                            <tr>
                                <td>
                                    <jsp:useBean id="dateValue" class="java.util.Date"/>
                                    <jsp:setProperty name="dateValue" property="time"
                                                     value="${event.timestamp}"/>
                                    <fmt:formatDate value="${dateValue}"
                                                    pattern="MM/dd/yyyy HH:mm"/>
                                </td>
                                <td>${event.amount}</td>
                                <td>${event.sourceUser.userAccounts.iterator().next().currentAmount}</td>
                                <td>${event.status}</td>
                                <td>${event.sourceUser.email}</td>
                                <td><c:if test="${event.status != 'SUCCESS'}">
                                    <input type="button" class="withDraw"
                                           value="подтвердить вывод"/>
                                </c:if>

                                    <div class="edit-holder  adt" id="">

                                        <div class="edit-box">
                                            <div class="title">Подтверждение вывода средств владельцем</div>
                                            <form action="/admin/confirmWithdrawRequest"
                                                  method="post">
                                                <div>
                                                    <input type="hidden" value="${event.id}" name="eventId"/>
                                                    <label>Статус</label>
                                                    <select name="status">
                                                        <c:forEach items="${statuses}" var="status">
                                                            <option <c:if test="${status == event.status}">
                                                                        selected="selected"
                                                                    </c:if>
                                                                    >${status}</option>
                                                        </c:forEach>
                                                    </select>
                                                    <div class="clear"/>
                                                </div>
                                                <div>
                                                    <label>Email</label>
                                                    <input type="text" class="with-draw-input" name="email"
                                                           value="${event.sourceUser.email}"
                                                           readonly/>
                                                    <div class="clear"/>
                                                </div>
                                                <div>
                                                    <label>Текущий баланс</label>
                                                    <input type="text" class="with-draw-input" name="balance"
                                                           value="${event.sourceUser.userAccounts.iterator().next().currentAmount}"
                                                           readonly/>
                                                    <div class="clear"/>
                                                </div>
                                                <div>
                                                    <label>Сумма запроса</label>
                                                    <input type="text" class="with-draw-input" name="email"
                                                           value="${event.amount}"
                                                           readonly/>
                                                    <div class="clear"/>
                                                </div>
                                                <div>
                                                    <label>Комментарий модератора</label>
                                                    <textarea class="moderationComment"
                                                              name="moderationComment">${event.moderationComment}</textarea>
                                                    <div class="clear"/>
                                                </div>
                                                <input type="submit" class="btn" value="сохранить"/>

                                                <div class="clear"></div>
                                            </form>
                                            <div class="close"></div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    ...

Now it is compiles good and I see expected result: enter image description here

I want to extract last td content to separated jsp like this:

<tbody>
                            <c:forEach var="event" items="${events}">
                                <tr>
                                    <td>
                                        <jsp:useBean id="dateValue" class="java.util.Date"/>
                                        <jsp:setProperty name="dateValue" property="time"
                                                         value="${event.timestamp}"/>
                                        <fmt:formatDate value="${dateValue}"
                                                        pattern="dd.MM.yyyy HH:mm:ss"/>
                                    </td>
                                    <td>${event.amount}</td>
                                    <td>${event.sourceUser.userAccounts.iterator().next().currentAmount}</td>
                                    <td>${event.status}</td>
                                    <td>${event.sourceUser.email}</td>
                                    <td><jsp:include page="confirmWithDrawModal.jsp"/>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>

and confirmWithDrawModal.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<c:if test="${event.status != 'SUCCESS'}">
  <input type="button" class="withDraw"
         value="подтвердить вывод"/>
</c:if>

<div class="edit-holder  adt" id="">

  <div class="edit-box">
    <div class="title">Подтверждение вывода средств владельцем</div>
    <form action="/admin/confirmWithdrawRequest"
          method="post">
      <div>
        <input type="hidden" value="${event.id}" name="eventId"/>
        <label>Статус</label>
        <select name="status">
          <c:forEach items="${statuses}" var="status">
            <option <c:if test="${status == event.status}">
              selected="selected"
            </c:if>
                    >${status}</option>
          </c:forEach>
        </select>
        <div class="clear"/>
      </div>
      <div>
        <label>Email</label>
        <input type="text" class="with-draw-input" name="email"
               value="${event.sourceUser.email}"
               readonly/>
        <div class="clear"/>
      </div>
      <div>
        <label>Текущий баланс</label>
        <input type="text" class="with-draw-input" name="balance"
               value="${event.sourceUser.userAccounts.iterator().next().currentAmount}"
               readonly/>
        <div class="clear"/>
      </div>
      <div>
        <label>Сумма запроса</label>
        <input type="text" class="with-draw-input" name="email"
               value="${event.amount}"
               readonly/>
        <div class="clear"/>
      </div>
      <div>
        <label>Комментарий модератора</label>
                                                        <textarea class="moderationComment"
                                                                  name="moderationComment">${event.moderationComment}</textarea>
        <div class="clear"/>
      </div>
      <input type="submit" class="btn" value="сохранить"/>

      <div class="clear"></div>
    </form>
    <div class="close"></div>
  </div>
</div>

and after this refactoring I see following result:

enter image description here

As you can see variables is not rendered.

How to fix it?

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
  • The _way_ you include the other JSP matters. See [this answer](http://stackoverflow.com/a/14763794/17300) on _[What's the difference between including files with JSP include directive, JSP include action and using JSP Tag Files?](http://stackoverflow.com/q/14580120/17300)_ – Stephen P Nov 18 '15 at 19:35
  • @Stephen P Do you think that jsp:include is wrong for my case? – gstackoverflow Nov 18 '15 at 19:40
  • Yes... the `<%@include ...>` is the form I think you want. See [this answer](http://stackoverflow.com/a/943789/17300) to _[Variables in jsp pages with "included" pages](http://stackoverflow.com/q/943770/17300)_ – Stephen P Nov 18 '15 at 20:17

2 Answers2

0

I have found 2 solutions:

  1. use <%@ include file="confirmWithDrawModal.jsp" %>
  2. use this advise https://stackoverflow.com/a/8003143/2674303

I am not sure which approach better

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
0

A .jsp file gets translated to a .java file, which is compiled and run, providing output that ultimately gets sent to the browser.

When you include another jsp within a jsp how those get translated and compiled depends on which form of include you use.

<jsp:include page="incpage.jsp"> translates and compiles mainpage.jsp and incpage.jsp separately and inserts the output of incpage.jsp at the include location. Thinking of this situation, incpage.jsp is independent of mainpage.jsp so (naturally) doesn't have access to those variables.

<%@include file="incpage.jsp"> is more like a C #include where the contents of incpage.jsp are copied into mainpage.jsp before translation and compilation take place. In this case it doesn't even matter if inpage has a .jsp extension.

If you want the included file to act as part of the main file, as it seems you do, you would use the second form of include — <%@include ...>

Stephen P
  • 14,422
  • 2
  • 43
  • 67