You can use following code for validating fields on the xpage:
if(getComponent("PersonName").getValue()=="" || getComponent("PersonName").getValue()==null)
{ ValidateMsg= ValidateMsg + " Person Name cannot be blank" + "\n"
return false;
}
}
if(getComponent("Email").getValue()=="" || getComponent("Email").getValue()==null)
{ ValidateMsg= ValidateMsg + " Employee Email cannot be blank" + "\n" }
if(getComponent("StartDate").getValue()==null )
{ ValidateMsg= ValidateMsg + " Start Date cannot be blank" + "\n" }
It just adds the validation message to a field ValidateMsg and then this field is passed to a custom control to display the warning to user.
Below is the code for the Custom control I had used to display the message box:
<?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>