- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2014 02:45 PM
I have created the attached HTML/Jelly script for a UI Page. I am having trouble with the following line in the script:
_max}">
When I manually initialize jvar_j to a value, such as:
The test in the j:while works fine. However, when I set it to a JavaScript variable, such as:
The test in the j:while fails and the while loop is never entered. I can't figure out what is going on. I have verified (via the javascript alert(...)) that the variables contain the correct values (i.e. jvar_j is less than jvar_storage_max). I believe it has something to do with setting the Jelly variable jvar_j equal to a JavaqScript variable? Or some kind of variable type mismatch?
I am completely stumped here. Any help would be much appreciated.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2014 03:34 PM
This looks tricky. Hopefully it is an easy fix. My guess is some sort of variable mismatch... have you tried running it with the browser dev tools turned on? It may be able to generate a useful error.
You can try calling a function to return the length instead of accessing the length directly. From the wiki on Jelly Tags: "var - The name of the variable that will be set to the result of the script. " It is worth a shot:
var clinChoices = { labels: [],
values: [],
clins: [],
length: 0,
getLength: function() {
return this.length;
}
};
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" expression="clinChoices.getLength();"/>
Also from the wiki on Jelly Tags: "jelly - If set to true, allows Jelly context variables to be referenced in the script. "
So:
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" jelly="true" expression="clinChoices.getLength();"/>
Perhaps this will expose jvar_max to the rest of the scripting context.
For troubleshooting, you can place a breakpoint statement right after you initialize the variables to see what isn't working/undefined.
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" expression="clinChoices.getLength();"/>
<g:breakpoint var="jvar_max" />
It will write to the system log the value of the variable where the breakpoint statement is encountered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2014 02:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2014 03:34 PM
This looks tricky. Hopefully it is an easy fix. My guess is some sort of variable mismatch... have you tried running it with the browser dev tools turned on? It may be able to generate a useful error.
You can try calling a function to return the length instead of accessing the length directly. From the wiki on Jelly Tags: "var - The name of the variable that will be set to the result of the script. " It is worth a shot:
var clinChoices = { labels: [],
values: [],
clins: [],
length: 0,
getLength: function() {
return this.length;
}
};
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" expression="clinChoices.getLength();"/>
Also from the wiki on Jelly Tags: "jelly - If set to true, allows Jelly context variables to be referenced in the script. "
So:
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" jelly="true" expression="clinChoices.getLength();"/>
Perhaps this will expose jvar_max to the rest of the scripting context.
For troubleshooting, you can place a breakpoint statement right after you initialize the variables to see what isn't working/undefined.
<j:set var="jvar_i" value="0"/>
<g:evaluate var="jvar_max" expression="clinChoices.getLength();"/>
<g:breakpoint var="jvar_max" />
It will write to the system log the value of the variable where the breakpoint statement is encountered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2014 10:11 AM
Justin,
Thanks for the suggestions. It turned out that Jelly was doing conversions between String and integer on my various counter variables. They both had to be integers for the comparison in the <j:while> tag to work. I was able to convert one of the jvar variables to an integer by adding '0' to the variable: <j:set var='jvar_abc' value = '${jvar_abc + 0}'/>. Once I did that, the tests worked fine. The <g:breakpoint var='jvar_abc'/> was critical because it showed both the value AND they type.
I've attached the final version of the script - I think it will help others to know about Jelly's silent variable conversions. I haven't seen anything about this on the forums.
Thanks again,
Daren