jinyoung kim jinyoung kim - 3 months ago 27
Java Question

using spring eval tag and call the java method in jsp without scriptlet

:-)

I have a one question.
I want to checked status on my checkbox When myCode.id and checkedLists code value same.

<c:forEach var="myCode" items="${myCodeList }" varStatus="status">
<tr>
<th>
<input type="checkbox" id="myCode${status.index}" name="myCodes" />
</th>
<td>
<textarea id="myContent${status.index}" name="myContents"></textarea>
</td>
</th>
</tr>
</c:forEach>


I toss myCodeList and checkedList from my Controller.
mycodeList is the list of the VO for some code list.
And checkedList is the list what I checked value from regist view.

<c:forEach var="myCode" items="${myCodeList }" varStatus="status">
<c:set var="myCodeFlag" value="false"
<tr>
<th>
<input type="checkbox" id="myCode${status.index}" name="myCodes"
<c:forEach var="checkedCode" items="${checkedList}">
<c:if test="${checkedCode.codId eq myCode.codId}">
checked="checked"
</c:if>
</c:forEach>
/>
</th>
<td>
<textarea id="myContent${status.index}" name="myContents"
<c:if test="${myCodeFlag eq flase}">disabeld="disabled"</c:if>>
<c:forEach var="checkedCode" items="${checkedList}">
<c:if test="${checkedCode.codId eq myCode.codId}">
${checkedCode.content}
</c:if>
</c:forEach>
</textarea>
</td>
</th>
</tr>
</c:forEach>


It works like what I want.

But my boss told me that change the code more simple.
Use the spring eval tag and call the java method,
It means using Java Lists method contain in JSP.

So I tried like this in JSP page.
${checkedList.contains('${myCode.codId }') }


But it doesn't work.
What can I do to fix the problem?

Thank for your help.

Have a nice day :-)

Answer

I change the way to solve it.

In Controller, change the List of Object's to the Map of Objects.

It means, I can write the code Like this.

Before.

<c:forEach var="myCode" items="${myCodeList }" varStatus="status">
  <c:set var="myCodeFlag" value="false"
  <tr>
    <th>
      <input type="checkbox" id="myCode${status.index}" name="myCodes" 
        <c:forEach var="checkedCode" items="${checkedList}">
        <c:if test="${checkedCode.codId eq myCode.codId}">
        checked="checked"
        </c:if>
        </c:forEach>
      />
    </th>
    <td>
      <textarea id="myContent${status.index}" name="myContents"
<c:if test="${myCodeFlag eq flase}">disabeld="disabled"</c:if>>
      <c:forEach var="checkedCode" items="${checkedList}">
        <c:if test="${checkedCode.codId eq myCode.codId}">
        ${checkedCode.content}
        </c:if>
      </c:forEach>
</textarea>
    </td>
</th>
</tr>
</c:forEach>

After.

    <textarea id="myContent${status.index}" name="myContents"
    <c:if test="${checkedCodeMap[checkCode.codValue].category.codId ne myCode.codId}">disabeld="disabled"</c:if>>
          <c:if test="${checkedCodeMap[checkCode.codValue].category.codId ne myCode.codId}">
${checkedCodeMap[checkCode.codValue].content}
          </c:if>
    </textarea>

It's better to read than before.