Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
456 views
in Technique[技术] by (71.8m points)

xpages - how to set a scope variable from client side javascript?

I'm trying to set an XPages scope variable from Client side JavaScript. I have an XPage which contains several sections which are shown or hidden using Dojo. On this XPage I have a button which executes some server side JavaScript. Once the SSJS behind the button executes, the section of the XPage which is visible by default is again visible, rather than the section which was visible immediately prior to the button being clicked. I would like the section which was visible prior to the button being clicked to also be visible after the SSJS behind the button has executed.

To do this I have thought of using a scope variable - use client side JavaScript to calculate which section of the XPage which is currently visible, set this value in a scope variable and read the scope variable in the onClientLoad event of the XPage to again make this section visible (and hide all other sections). However, I have found no way of setting a scope variable from client side JavaScript. I have tried adding

var xyz = "#{javascript:viewScope.put('sectionDisplay','Section')}"

to the onClick client event of the button but this sets the scope variable regardless of whether the button is clicked or not.

Before XPages, I would have used the querystring to pass variable from one page to another. How can I now do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot set the CSJS variable this way: If you add this code to your CSJS, it will be calculated before sent to the browser. That is why the variable is set regardless of a click onto the button.

But you can add some SSJS code to your button which sets the viewScope variable. You can send the value from the browser with a parameter as described here: http://xpageswiki.com/web/youatnotes/wiki-xpages.nsf/dx/Work_with_events_and_partial_or_full_refresh#Run+a+partial+update+from+client+javascript

EDIT:

You can access different parameters with the param object in SSJS. F.e. if you add the parameter value in your CSJS...

XSP.partialRefreshGet( id, {
    params: { 'value': 'some string'}
});

... you can access the parameter in SSJS like this:

param.get("value");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...