user2971160 February 2016

setting id for tr(table row ) not working

Jsp Code:

<tbody>
                    <c:forEach items="${noteList}" var="note" varStatus="count">
                        <tr id="<c:out value="${count.count}"/>">
                            <td id="noteType${count.count}">
                                Transaction Note
                            </td>
                            <td id="noteEnteredDate${count.count}">${note.formattedEnteredOn}</td>
                            <td id="noteEnteredBy${count.count}">${note.formattedUserInitials}</td>
                            <td id="noteContent${count.count}">${note.noteText}</td>
                        </tr> 
                    </c:forEach> 
                </tbody>

front end view

view source code for above screen shot

what would be the issue for not generating tr id

Answers


Aleksey Bykov February 2016

Use single quotes instead of double. This will work:

<tbody>
    <c:forEach items="${noteList}" var="note" varStatus="count">
        <tr id="<c:out value='${count.count}'/>">
           ...
        </tr> 
    </c:forEach> 
</tbody>

Updated. This JSTL code -

<table>
<thead></thead>
<tbody>
<c:forEach items="${noteList}" var="note" varStatus="count">
    <tr id="<c:out value='${count.count}'/>">
        <td id="noteType${count.count}">
            Transaction Note
        </td>
        <td id="noteEnteredDate${count.count}">1</td>
        <td id="noteEnteredBy${count.count}">2</td>
        <td id="noteContent${count.count}">3</td>
    </tr>
</c:forEach>
</tbody>
</table>

Generates the following HTML markup -

<table>
<thead></thead>
<tbody>

    <tr id="1">
        <td id="noteType1">
            Transaction Note
        </td>
        <td id="noteEnteredDate1">1</td>
        <td id="noteEnteredBy1">2</td>
        <td id="noteContent1">3</td>
    </tr>

    etc...

</tbody>

The issue also may be in the fields of the objects. For example, noteText field may contain special characters. For example, the closing tag - </table>.

<c:set var="str" value="</table>"/>

Then we get something like this -

enter image description here

The fn:escapeXml() function escapes characters that could be interpreted as XML markup. As a result in the following case -

<td id="noteContent${count.count}"&g 

Post Status

Asked in February 2016
Viewed 3,093 times
Voted 14
Answered 1 times

Search




Leave an answer