简体   繁体   English

有什么办法可以在客户端使用javascript更改jsp自定义标签值

[英]Is there any way to change the jsp custom tag value using javascript at clientside

My intention is to change my jsp custom tag value using javascript at client side. 我的意图是在客户端使用javascript更改我的jsp自定义标记值。 The the tag is giving some date value. 标签提供了一些日期值。 Before redering the value I'm calling javascript function and trying to do required changes on it and returning the result date. 在重新赋值之前,我正在调用javascript函数并尝试对其进行必要的更改并返回结果日期。 But failing to handle jsp tag and javascript according to my requirement. 但是无法根据我的要求处理jsp标签和javascript。 I did like this.. 我确实喜欢这个

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/fmt.tld" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script>
var createdDate;
window.onload = function() {
createdDate = '${myBean.createdDate}';
    // modifying the createdDate 
}
function getModifiedDate(){
return createdDate;
}
</script>
<table>
.
.
.
<tr><td>
 <!-- I modified the code like this -->
<fmt:formatDate value='<script>getModifiedDate();</script>'  type="both" pattern="${viewDatePattern}" />
</td></tr>
.
.
.
</table>

previously it is like this.. 以前是这样的。

<fmt:formatDate value="${myBean.created}" type="both" pattern="${viewDatePattern}" /> 

I executed the application with my changes but no luck,please provide the solution to render the date value through the tag after its modification from the script. 我执行了我的更改但没有运气的情况下执行了该应用程序,请提供一种解决方案,以在脚本对日期值进行修改后通过标记来呈现日期值。

I came up with one kind of solution for this, prior to that I missed out few things while posting the question.. JSP and its tags(inbuilt/custom) are something related to service side but not for client browser. 在此之前,我想出了一种解决方案,在发布问题之前,我错过了几件事。.JSP及其标签(内置/自定义)与服务端相关,但与客户端浏览器无关。 JSP engine writes a servlet according to tags what we written in our jsp page. JSP引擎根据我们在jsp页面中编写的标签编写servlet。 we can call jsp some tags inside javascript function but calling a javascript function inside a tag cannot be possible. 我们可以在javascript函数内调用一些jsp标记,但是不能在标记内调用javascript函数。 For above scenario, I wrap the rendered tag value with a <div> , and located this tag inside the javascript function and did my modifications on the rendered data and then set the result as innerHTML of same <div> .. here is the approach.. 对于上述情况,我用<div>包装呈现的标记值,并将此标记放置在javascript函数内,并对呈现的数据进行了修改,然后将结果设置为相同的<div> innerHTML。 ..

  <div id="requestDateId" style="height: 5px;">
    <fmt:formatDate value="${myBean.created}" type="both" />
    </div>   

inside script.. 内部脚本

<script>
  window.onload = function() {
    var requestDate = document.getElementById("requestDateId").innerHTML;
    if(requestDate)
    document.getElementById("requestDateId").innerHTML = foo(requestDate);
  }
  function foo(requestDate){
     // my logic 
    return requestDate;
  }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM