Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting to scope variables in client side javascript (CSJS) on XPages

Tags:

xpages

I am setting a viewScope variable in a server side javascript (SSJS) button.

viewScope.put("branchName",doc.getItemValueString("BranchName"))

How can I access that variable on the client side?

like image 506
Bruce Stemplewski Avatar asked Mar 05 '12 14:03

Bruce Stemplewski


1 Answers

If you need to access the viewScope variable from a client side script you can use the xp:scriptBlock tag to setup a number of global javascript variables.

<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[var myVar = #{javascript:viewScope.get("scopeVar")}]]></xp:this.value>
</xp:scriptBlock>

The main problem with this method is that the inner server side javascript is only computed when that element is initially rendered or when a partial refresh is performed on the element so there is no guarantee that the client side JS variable is set to the correct value.

like image 175
Declan Lynch Avatar answered Dec 24 '22 18:12

Declan Lynch