Trigger Apache Velocity #set Parameter using a button (HTML / JS)

1.6k views Asked by At

Is it possible to trigger a Velocity Template Language #set value to parameter via a button?

I am trying to combine HTML, JS and Velocity doing the following:

#set($ld=$pageParameters.Work_Item_Link_Direction.values)

<button id="demo2">up</button>

<script>
document.getElementById('demo2').onclick = function() {
   #set( $ld = "up" )
   alert("button2 was clicked");
};
</script> 

The part, however, which doesn't work in this code is:

#set ( $ld = "up")

as it isn't pure JavaScript.

Any hints or ideas how I can combine anyway this "#set value to parameter" as function onclick to the button? I am working inside the application Polarion ALM.

Or is there any other approach how I can set a value to a (page) parameter using velocity and using a Button?

1

There are 1 answers

2
Claude Brisson On BEST ANSWER

There is a little misconception, here:

  • the Velocity Template Language code is evaluated at the time the page is sent by the HTTP server, on the server itself.
  • the Javascript code is evaluated once the page is loaded, in the browser.

So what you ask for doesn't really make sense.

What you can do, however, is trigger an ajax call from inside your javascript handler, which can set some value inside the session, return some value to the success ajax handler, etc.