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



Apr 9, 2013, 6:57 AM
67 Posts
topic has been resolvedResolved

Server side value in CSJS

  • Category: Dojo and Client Side JavaScript
  • Platform: All
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 9
 Hi,
 
i've embedded a CS script (that works):

 <xp:script clientSide="true">
function({ 
ean: '4021972002188'
    }); 
</xp:script>


Now, the param 'ean' should be a serverside viewScope value.I've tried this  (that does'nt work): 
 
 <xp:script clientSide="true">
function({ 
ean: <![CDATA[#{viewScope.get('EAN')};}]]>
     }); 
</xp:script>
 
What is the best way to do this ??

Thanks 
Uwe 
Apr 9, 2013, 8:43 AM
53 Posts
Re: Server side value in CSJS
You can't get scoped variables in csjs at all. There's a question on stack overflow about it here http://stackoverflow.com/questions/9568519/getting-to-scope-varibles-in-client-side-javascript-csjs-on-xpages

 
It suggests using field values to store the viewscope values, including using hidden fields (which I've done successfully) 
Apr 9, 2013, 9:31 AM
54 Posts
Re: Server side value in CSJS
Try this in CSJS:

console.log("#{javascript:viewScope.EAN}") 
Apr 9, 2013, 10:34 AM
67 Posts
Re: Server side value in CSJS
 That doesn't work.
 
All Expressions like
#{javascript:viewScope.EAN}

are failing in the clientside script block.
The evaluator of the editor doesn't allow to save this, because there is a 'content  with runtime binding'.
 
Are there any other proposals ?
Idea: i write the whole script block serverside as pure HTML Code in a text field. Then i can embed the value. 
 
@Dan:
i don't know to integrate XSP.getElementById("#{id:inputHidden1}").value into my csjs ???
Nevertheless I think that would be the same problem as described above.
 
 
Apr 9, 2013, 11:47 AM
54 Posts
Re: Server side value in CSJS
Why did you use a xp:script tag and not a xp:scriptblock tag??


This wirks for me:

<xp:scriptBlock id="scriptBlock1">
        <xp:this.value>

 <![CDATA[var dd =function(){
ean = "#{javascript:viewScope.ean}";
console.log(ean);
}]]></xp:this.value>
    </xp:scriptBlock>  
Apr 9, 2013, 1:58 PM
67 Posts
Re: Server side value in CSJS
Helmut,

i didn't know xp:scriptBlock, that works !

The block is now in the client sourcecode in the body section (in the header it wasn't possible).
But it doesn't run once at loading. How can i achive that ?

Thanks
Uwe 

 
Apr 9, 2013, 2:53 PM
54 Posts
Re: Server side value in CSJS
You have to call the function to get the value.

I didn´t know at what time you need it. 
Apr 9, 2013, 3:24 PM
366 Posts
Re: Server side value in CSJS
 If you are using 8.5.3, instead of the scriptblock you add your function to the XPage onClientLoad event for client side script.


It adds the function to the header and then the function can be called from any CSJS on the page
Apr 18, 2013, 12:51 PM
67 Posts
Re: Server side value in CSJS
Thank you all.
It is solved. I've choosed Helmuts way: 


 <xp:scriptBlock>
  <xp:this.value>
<![CDATA[#{javascript:"XSP.addOnLoad(function({" + viewScope.get('EAN') + "}));"
                         }]]>
</xp:this.value>
</xp:scriptBlock>

This loads clientside and has the serverside value in it. 

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