开发者

html select option tag closes itself due to a "/" character in the dynamic value (JSP, JSTL)

<select id="ordersSelect" class="drop-down" onchange="somemethod()"> 

<c:forEach items="${orders}" var="order" varStatus="orderStatus">
  <option value="${order.id}"> ${order.publicId} </option>
</c:forEach>

</select>

I have the above peice of code in a JSP page, that receives a list of Orders and each order has some information, the particular information that I want to display in a SELECT field is the publicId.

The problem is that, on display there is only one OPTION in the SELECT and the rest of the order's publicId s are displayed as normal text below the SELECT box and not an OPTION to select.

I found out that the public开发者_如何学运维Id actually contains a String like A10/0001/0 and that is the character "/" is most probably causing the problem.

Any solutions/suggestion/ideas?


This is more likely caused by a doublequote " in the option value. At any way, you need to escape HTML entities. You can use JSTL's fn:escapeXml() for this.

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

...

<option value="${fn:escapeXml(order.id)}">${fn:escapeXml(order.publicId)}</option>


I'm not sure that is the problem. I have created the following static HTML and it works in Firefox and Internet Explorer 8.

<select id="ordersSelect" class="drop-down" onchange="somemethod()"> 
    <option value="A100/000/00">A100/000/00</option>
    <option value="A100/000/00">A100/000/00</option>
    <option value="A100/000/00">A100/000/00</option>
</select>

Feel free to let me know what browser you are using and maybe post the "final" html output of your page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜