how to pass parameter value from a jquery function to struts2 url tag

旧城冷巷雨未停 提交于 2019-12-02 17:21:43

问题


i am trying to pass parameter from a jquery function. Everything is fine but only problem is passing the parameter value rowObject.themeScreenshot

 <script type="text/javascript">
   function formatLink(cellvalue, options, rowObject)
     {    
        var para=rowObject.themeScreenshot; //here value is coming fine 
        alert("Json object value-"+para);  //correctly i am geting the value of para.
        return "<a style='cursor:pointer;' onClick='javascript:openDialog("+cellvalue+")'><img src='<s:url action='ImageAction' namespace='/myimage/secure'><s:param name='imageId'>"+para+"</s:param></s:url>'></a>";
     //this is returning url with empty imagId  output in url:-http://localhost:8080/visionbooks/myimage/secure/ImageAction?imageId=  
   }

What i want is:-

http://localhost:8080/visionbooks/myimage/secure/ImageAction?imageId=anyvalue

But currectly i am geting output is :

http://localhost:8080/visionbooks/myimage/secure/ImageAction?imageId="+para+" variable name is passing as prameter value.Why?

Please help me to solve this problem.


回答1:


Struts 2 tags are evaluated at page render time, which is far before your script runs.

If you check the source code of the page you will see those tags have been converted to regular html elements. So it the para javascript variable would not be evaluated.

You can try to update the return line to

return "<a style='cursor:pointer;' onClick='javascript:openDialog("+cellvalue+")'><img src='<s:url action='ImageAction' namespace='/myimage/secure'></s:url>" + "?imageId="+para+ "'></a>";


来源:https://stackoverflow.com/questions/13923995/how-to-pass-parameter-value-from-a-jquery-function-to-struts2-url-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!