This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Aug 24, 2011, 7: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, 4: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...

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal