最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - assign javascript variable to a velocity template variable - Stack Overflow

programmeradmin0浏览0评论

In my velocity template, I have a javascript variable like

var workflowInstanceNameText = document.getElementById('workflowInstanceName').value;

and I want to assign the javascript variable to velocity template variable.

#set(workflowName = 'someexpression here');

In the palce of some expression I have tried as below but its not assigning value

 #set(workflowName = workflowInstanceNameText);
 #set(workflowName = $workflowInstanceNameText);

Any help is appreciated.

Thanks in advance.

In my velocity template, I have a javascript variable like

var workflowInstanceNameText = document.getElementById('workflowInstanceName').value;

and I want to assign the javascript variable to velocity template variable.

#set(workflowName = 'someexpression here');

In the palce of some expression I have tried as below but its not assigning value

 #set(workflowName = workflowInstanceNameText);
 #set(workflowName = $workflowInstanceNameText);

Any help is appreciated.

Thanks in advance.

Share Improve this question edited Sep 24, 2012 at 15:37 Vikdor 24.1k10 gold badges65 silver badges85 bronze badges asked Sep 24, 2012 at 7:25 NPKRNPKR 5,5064 gold badges34 silver badges48 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Velocity works on server side. JavaScript works on client side (browser). You can generate JavaScript using Velocity, but not the other way around.

Velocity templating happens on the server side. So, if you want your javascript variable that is on the client-side to be available during velocity template stage on the server side, you have to send that variable as a request parameter to your server-side servlet/action and refer to that request parameter in your velocity template.

发布评论

评论列表(0)

  1. 暂无评论