user2446292
user2446292

Reputation: 63

Using view.postscript in xpages

I have a xpage that use view.postscript like this:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
 <xp:this.resources>
 <xp:dojoModule name="dojox.widget.Toaster"></xp:dojoModule>
 <xp:styleSheet href="/.ibmxspres/dojoroot/dojox/widget/Toaster/Toaster.css"></xp:styleSheet>
 </xp:this.resources>

 <xp:scriptBlock id="scriptBlock1">
 <xp:this.value><![CDATA[var Toaster = function(id, msg, type, duration, pos) {
 type = (type == null) ? "message" : type;
 duration = (duration == null) ? "5000" : duration;
 pos = (pos == null) ? "br-up" : pos;

 var obj = dijit.byId(id);
 obj.positionDirection = pos;
 obj.setContent(msg, type, duration);
 obj.show();
}]]></xp:this.value>
 </xp:scriptBlock>

 <xp:div id="toaster" themeId="toaster" dojoType="dojox.widget.Toaster"></xp:div>

 <xp:button value="Toaster" id="button1">
 <xp:eventHandler event="onclick" submit="true"
 refreshMode="complete">
 <xp:this.action><![CDATA[#{javascript:view.postScript("Toaster('"+getComponent("toaster").getClientId(facesContext)+"', 'toaster message!')");}]]></xp:this.action>
 </xp:eventHandler>
 </xp:button>
</xp:view>

But when I click button,the toaster can't show.Why? And I need a way to show the toaster called by ssjs function. Thanks a lot.

Upvotes: 0

Views: 1381

Answers (1)

Aaron Brake
Aaron Brake

Reputation: 370

As @Frantisek Kossuth said, you're re-submitting the page. When your refreshMode is complete it will re-render the page based on the server values. If you want to make client side changes and reflect them in your UI, you can't do a refresh of complete. Doing a partial refresh of the page on an element that won't change (like button1) should update your UI without rebuilding the page.

Similarly, why do you need this to be done through SSJS? Why not just use Client actions in your button activation? If this isn't part of a larger function call that you're not including, simply change the event code from Server to Client and call the Toaster function that way. This would also allow you to not have to submit anything, leaving submit="false" in your eventHandler to avoid unnecessary functionality.

Upvotes: 1

Related Questions