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



Jun 13, 2012, 6:54 AM
12 Posts

Alert or prompt in Server side Javascript

  • Category: Server Side JavaScript
  • Platform: Other
  • Release: 8.5.3
  • Role: Developer
  • Tags:
  • Replies: 5
How to print validation message in server side javascript as we do in client side javascript using alert.
 
 
That is Consideer we have 3 edit boxes named a,b,c.
 
In CSJS:
we check if field=="" and send alert("Pls fill the a,b,c fields")
 
Like wise in SSJS how to do it?????
 
Jun 13, 2012, 7:42 AM
10 Posts
Re: Alert or prompt in Server side Javascript
 This depends on how you are doing your validation.
 
If you are using the standard validators that are properties of the xPages controls, then you can simply set the message property for the validator, and then use Display Error or Display Errors controls to display the message when validation fails (i.e. your code returns false). 
 
If however you are trying to create your own SSJS in a script library to validate then add the following function to your code:
 
function postValidationError(control, msg) {
    if ((typeof msg) != "string")
            return;
    var msgObj = new javax.faces.application.FacesMessage(
    javax.faces.application.FacesMessage.SEVERITY_ERROR, msg, msg);
    facesContext.addMessage(control.getClientId(facesContext), msgObj);
    control.setValid(false);
}
 
This will send the message you pass in to the Display Error control for the field you are validating. 
Jun 13, 2012, 8:49 AM
12 Posts
Re: Alert or prompt in Server side Javascript
Thanks in advance.
 
But can you be bit clear in guiding as a result I can implement them and see.. Because am newbie in ssjs validation. I can do csjs validation. Pls be step wise for doing.
Jun 13, 2012, 11:11 AM
25 Posts
Re: Alert or prompt in Server side Javascript
Hi Srividhya,

Simply you can do it  by designing custom message box as below,

1. Design custom control for showing message which will include computed field (default value set to session scope variable) for display error and image control for showing failure image like crossing.
2. Add dialog box on xpage for which you want to show an error through ssjs
3. Place newly design custom control in dialog box.
4. In ssjs script, when error occurred, set that session scope field value.
5. Show dialog box like dialog name.show() and return false.
 
best luck :)
Jun 13, 2012, 12:06 PM
12 Posts
Re: Alert or prompt in Server side Javascript
Hi Swapnil,
 
 
Thanks and Nice of you..
 
I have created a Custom control with a computed field.
That computed field is mapped to Session scope with variable name displayerror
 
Then added Dialog with the custom control in it.
 
But i don find anything working..
 
Can you help me out pls
Jun 14, 2012, 10:14 AM
26 Posts
Re: Alert or prompt in Server side Javascript
Here is the CC to show validation msg to the user.
 
on the OK button in the msgbox control, you need to add the below code line:

getComponent("MsgBoxDialog").hide().

In the validation funciton or script,put the validation msg to a var, in this case it is: ValidateMsg.

if (ValidateMsg!="")
    {  getComponent("MsgBoxDialog").show()
       getComponent("ValidateMsgBox").setValue(ValidateMsg)
       return false;
    }

Please note that MsgBoxDialog is the name of the Dialog box.
The combo box where messages are stored, its name is: ValidateMsgBox
 
Let me know if any questions.
 
Regards,
Pranesh Vaidya
 
 
Here is the XML code for the custom control:
 
 <?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
    xmlns:xe="http://www.ibm.com/xsp/coreex" dojoTheme="true"
    dojoParseOnLoad="true" dojoForm="true">

    <xp:this.resources>
        <xp:dojoModule name="dijit.form.Button"></xp:dojoModule>
    </xp:this.resources>

    <xe:dialog id="MsgBoxDialog" title="Message">
        <xp:panel>
            <xp:inputText id="action"
                style="width:75.0px; display:none">
            </xp:inputText>
            <xp:table style="width:100%">
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td></xp:td>
                </xp:tr>
                <xp:tr>
                    <xp:td>
                        <xp:image id="image1" style="height:42.0px">
                            <xp:this.url><![CDATA[#{javascript:if (getComponent("ValidateMsgBox").getValue()!= null) { return("/fail.png");}
else {return("/success.png");}}]]></xp:this.url>
                        </xp:image>
                    </xp:td>
                    <xp:td>
                        <xp:text escape="true" id="MsgBox">

                        </xp:text>
                        <xp:inputTextarea id="ValidateMsgBox"
                            readonly="true">
                            <xp:this.multipleSeparator><![CDATA["\n"]]></xp:this.multipleSeparator>
                        </xp:inputTextarea>
                    </xp:td>




                </xp:tr>
                <xp:tr>
                    <xp:td></xp:td>
                    <xp:td align="center">
                        <xp:button value=" OK " id="button2"
                            style="text-align:center;width:56.0px">
                            <xp:eventHandler event="onclick"
                                submit="true" refreshMode="complete" id="eventHandler1">
                                <xp:this.action><![CDATA[#{javascript:getComponent("MsgBoxDialog").hide()

}]]></xp:this.action>
                            </xp:eventHandler>
                        </xp:button>
                    </xp:td>




                </xp:tr>
            </xp:table>


        </xp:panel>



    </xe:dialog>
    <xp:br></xp:br></xp:view>

 

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