0

I need the following logic to occur:

  1. Get the shippingDate from the db
  2. If the shippingDate has value (not empty), display it
  3. Otherwise, set the shippingDate that is displayed on the page to today's date. This way the user can just submit the page and the default value (today's date) will be written to db. The user can also choose to change that value.

This is what I have so far:

myJsp.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<% String todaysDate = cm.GetMonth() + "/" + cm.GetDay() + "/" + cm.GetYear();%>
...
 <c:forEach var="i" items="${bean.results}">
     <c:choose>
         <c:when test="${empty i.shippingDate}">
             <c:set var="shippingDate" value="<%=todaysDate%>" scope="request"></c:set>
         </c:when>
     </c:choose>
 <TD>
     <INPUT TYPE="text" NAME="shippingDate" id="shippingDate" value="${i.shippingDate}"/>                            
 </TD>

Above code works when there is value in db, but it doesn't set shippingDate to today's date if nothing is returned from db.

Does anyone see what I am doing wrong?

Angelina
  • 2,175
  • 10
  • 42
  • 82
  • What result will you get on ``? It seems you set local variable `shippingDate` whithout changing `i.shippingDate`. – mr.tarsa Jul 22 '16 at 13:41
  • @tarashypka that's true, if I set value="${shippingDate} then I get todaysDate, for the values that have something in db, I get nothing :( – Angelina Jul 22 '16 at 13:44

1 Answers1

1

You can create another variable and assign it appropriately:

<c:forEach var="i" items="${bean.results}">
  <c:choose>
    <c:when test="${empty i.shippingDate}">
      <c:set var="inputDate" value="<%=todaysDate%>" scope="request"/>
    </c:when>
    <c:otherwise>
      <c:set var="inputDate" value="${i.shippingDate}" scope="request"/>
    </c:otherwise>
  </c:choose>
  <td>
    <input type="text" NAME="shippingDate" id="shippingDate" value="${inputDate}"/>                            
  </td>
  ...
mr.tarsa
  • 6,386
  • 3
  • 25
  • 42