[xwiki-devs] Passing values from Velocity templates to HTML on the wiki page
THANK YOU SERGIU. About my question on passing values back from .vm file to the wiki page where I call the .vm file: The reason I am using a template is that there is a select box on that wiki page and some information needs to be fetched based on the value user selects. To be able to use the value selected by the user, I need to do an HTML Post first. so, I submit the form and the values are processed by a template and now I need to display the value calculated in the template, on my xwiki page. I tried some stuff but did not work. So, now I am actually creating an object on that page and set its properties with the value calculated in the template. any other better way of doing this? Is it possible to access the selected value on the wiki page without doing a post? what does $!{value} provide...I do not understand the ! before the variable name. On another note: In the object solution for this problem, I try to set the object property (of type Number) with a velocity variable which also has a numeric value. when I save the document after setting the object values, it gives me an exception on the "save" method. Error number 3201 in 3 Wrapped Exception: java.lang.Integer I checked the type of Number for that property and changed it from long to Integer in the class editor but, it still gives this error. I am also setting a boolean value in the object. I noticed that the boolean fields take values 0 or 1 but display them as No or Yes. So, when we "get" we get Yes/No and when we "set" we have to set 0 or 1. could that be causing the exception? I ma not sure what is causing this exception. but when I hit the back button, I see the values of the object properties set appropriately and displayed. Only when I do the $response.sendRedirect with "save", it throws the exception. Do I need to use Util.parseInteger or Util.toNumber in any of these cases (before setting the Object property value to a number) Please advice. Thanks a lot Kamna
On Wed, May 21, 2008 at 7:25 PM, Kamna Jain <[email protected]> wrote:
The reason I am using a template is that there is a select box on that wiki page and some information needs to be fetched based on the value user selects. To be able to use the value selected by the user, I need to do an HTML Post first. so, I submit the form and the values are processed by a template and now I need to display the value calculated in the template, on my xwiki page.
To display some values passed to a wiki page (either with a GET or a POST) you can do the following : $request.myfirstvaluekey $request.myfirstvaluekey If you have a set of values that are passed under the same key you can do : $request.getParameterValues("mymultiplevalueskey")
I tried some stuff but did not work. So, now I am actually creating an object on that page and set its properties with the value calculated in the template.
any other better way of doing this?
Doing it without a vm template I guess.
Is it possible to access the selected value on the wiki page without doing a post?
what does $!{value} provide...I do not understand the ! before the variable name.
The default velocity is to print the call if it returns null, for example if you put $mynonexistingvariable in a wiki page it will be displayed, the ! is meant to avoid this default behavior, $!mynonexistingvariable won't print anything in the rendered page.
On another note: In the object solution for this problem, I try to set the object property (of type Number) with a velocity variable which also has a numeric value. when I save the document after setting the object values, it gives me an exception on the "save" method. Error number 3201 in 3 Wrapped Exception: java.lang.Integer
I checked the type of Number for that property and changed it from long to Integer in the class editor but, it still gives this error. I am also setting a boolean value in the object. I noticed that the boolean fields take values 0 or 1 but display them as No or Yes. So, when we "get" we get Yes/No and when we "set" we have to set 0 or 1. could that be causing the exception?
I ma not sure what is causing this exception. but when I hit the back button, I see the values of the object properties set appropriately and displayed. Only when I do the $response.sendRedirect with "save", it throws the exception.
Do I need to use Util.parseInteger or Util.toNumber in any of these cases (before setting the Object property value to a number)
Can you paste your velocity snippet here with the details about the types of the properties used in it ? -- Jean-Vincent Drean
participants (2)
-
Jean-Vincent Drean -
Kamna Jain