1

I have a client-side script in which I initiate some SSJS to collect string values that reside in a strings.properties file:

function confirmBeforeDelete(){
    var msgEmptySelection = "#{javascript:strings['empty']}";
    var msgConfirm = "#{javascript:strings['confirm']}";
    if(!XSP.isViewPanelRowSelected("#{id:vwPnlDefault}", "col1")) {
        !XSP.alert(msgEmptySelection);
        return false;
    }
    if(!XSP.confirm(msgConfirm)) {return false;}    
}

This works fine. But when I store the script in a csjs library my text messages becomes: #{javascript:strings['empty']} and #{javascript:strings['confirm']}. What am I doing wrong?

Malin
  • 697
  • 5
  • 21

1 Answers1

6

You can't put CSJS code with SSJS parts into a CSJS library. The SSJS part gets executed on server first and the modificated code is sent to client then. A CSJS library is sent to client unchanged. That's why you see the SSJS code there.

You can add parameters to your function

function confirmBeforeDelete(msgEmptySelection, msgConfirm, vwPnlDefaultId){
    if(!XSP.isViewPanelRowSelected(vwPnlDefaultId, "col1")) {
        !XSP.alert(msgEmptySelection);
        return false;
    }
    if(!XSP.confirm(msgConfirm)) {return false;}    
}

so that the function is pure CSJS code and can be stored in a CSJS library.
You'd call your function in XPage with the parameters:

confirmBeforeDelete("#{javascript:strings['empty']}", "#{javascript:strings['confirm']}", 
                    "#{id:vwPnlDefault}")
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67