Sunday, December 12, 2010

JSP Page ( JSTL using ) - > Generate Javascript ( Expression Language using ) with same system tag script

Энэ жишээ нь JSP бичих үед тулгардаг ( тодотговол өгөгдлийн санд ' болон " тэмдэгтүүд бүртгэгдсэний дараа javascript object болгоход мөн click=" event доторхи үйлдэл дээр дээрх тэмдэгтээс болж алдаа заадаг " )  асуудлыг шийднэ.

using 1

<c:if test="${programehasblock_programehasblocks.totalNumberOfElements > 0}">
    <script type="text/javascript">
        $(function() {
        <c:forEach items="${programehasblock_programehasblocks.thisPageElements}" var="row" varStatus="status">
            _initItem(${row.id}, eval('('
                    + "{ id: ${row.id},"
                    + "name:'<gtx:replace strValue="${row.name}" oldStr="\"" newStr="\\\&quot;"/>',"
                    + "time:\"<fmt:formatDate value="${row.starttime}" pattern="yyyy.MM.dd HH:mm:ss"/>\",description:'${row.descr}' }"
                    + ')'));
        </c:forEach>
        });
    </script>
</c:if>

using 2

<c:choose>                                                                        <c:when test="${!empty row.anyid}">
                                                                            <a href="javascript:void(0);"
                                                                               onclick='_addItem(${row.id},"<gtx:replace strValue="${row.name}" oldStr="\"" newStr="\\\&quot;"/>",${row.age},${row.anyid});'>нэмэх</a>
                                                                        </c:when>
                                                                        <c:otherwise>
                                                                            <a href="javascript:void(0);"
                                                                               onclick='_addItem(${row.id},"<gtx:replace strValue="${row.name}" oldStr="\"" newStr="\\\&quot;"/>",${row.age},0);'>нэмэх</a>
                                                                        </c:otherwise>                                                                    </c:choose>




<script>_addItem(obj){alert(obj.name);};</script> гэх мэт үйлдлийг өөрсдөө бичнэ.
<gtx:replace нь текст сольдог tag ( Expression Language ) юм.

No comments: