FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.



Aug 24, 2011, 3:37 PM
6 Posts

Does anyone know how these brackets got added to my string in SSJS?

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 8.5.2
  • Role:
  • Tags:
  • Replies: 1
 Can someone explain how the value of a variable in my server side javascript got changed on me?
 
Here's the code for a Visible formula of a table I created in a control: 
 
var showLoc = false;
var choiceStr = getComponent("listBox1").getValue();
if (choiceStr != null){
//_dump("choiceStr = " + choiceStr);
if (choiceStr.indexOf(",") == -1){
//_dump("choiceStr is running. Value = " + choiceStr.toString());
if(choiceStr == "[1]"||choiceStr == "[2]"||choiceStr == "[3]"){
showLoc = true;
}
}else{
var choices = choiceStr.split(",");
for(i = 0;i < choices.length;i++){
//_dump("choice array populated. position " + i + " is " + choices[i]);
if(choices[i] == "1"||choices[i] == "2"||choices[i] == "3"){
showLoc = true;
}
}
}
}
return showLoc; 
 
 Here's the bizarre bit--if I check the value of choiceStr before I do the indexOf method (the first commented out _dump statement), the value does not have brackets, and it seems to be treated like an array if there are multiple values selected. If I check it AFTER the indexOf method (the second commented out _dump statement), the brackets are added to the string. If there are multiple values, the array gets created by the split (third commented out _dump statement) and there are no brackets.
 
I was able to make this code work by adding the brackets, but I'm wondering how they got there in the first place. Anyone know? 
 
Thanks. 
 
brandt 
Aug 31, 2011, 12:55 PM
64 Posts
Search for "java.faces.component.UIComponent" to see what getValue() returns..
- While "help" says getComponent() returns a java.faces.component.UIComponent, it doesn't deign to indicate anything about that class, or the many myriads of derivatives that JSF employs from it.  Fortunately google should come to the rescue.  I suspect getValue() is returning a Vector and the SSJS -> Servlet automagic isn't working correctly.  If this is the case, setting choiceStr to be a Vector explicitly, or otherwise explicitly data typing it in some manner, may work consistently.
 
Hope this helps...

FORUM PLAN UPDATE
Date revision: This forum will remain open to new posts and responses until December 1, 2018. (After that date, you will still be able to view and search the forum.) Also, we're taking a second look at the best place to host future conversation. For now, keep using this forum, and stay tuned for more news.