Search code examples
notificationsdialogxpagesxpages-ssjs

P.notify like message with variable message


in an Xpage , I'm looking for a message box like p.notify that gives a personalised message that fade's in and out automatically in my onclick of a button event.

in client side I put : $.pnotify({ pnotify_title: 'Test',pnotify_text: 'personalised message'}); Which works , but how do I put a personalised text in it from for example a viewScope

in server side I put : view.postScript("$.pnotify({ pnotify_title: 'Test',pnotify_text: 'personalised message'});"); Which gives an error : Uncaught TypeError: Cannot read property 'top' of undefined at Function.pnotify (jquery.pnotify.min.js:37) at demo.xsp:306

So my question : How can I put a personlised message (from for example a viewScope into the client side script , or is there a way to make my server side script to work or is there another way to get the same result ( I don't think there's a way to autoclose xpages dialogs after some time?)


Solution

  • In the a clientside event of any XPages control you can add serverside code, for example:

    <xp:button
        value="Show message"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="false">
            <xp:this.script><![CDATA[
            $.pnotify({ 
              pnotify_title: 'Test',
              pnotify_text: '#{javascript:viewScope.yourVar}'
            });]]></xp:this.script>
        </xp:eventHandler>
    </xp:button>
    

    Does that work in your situation?