Search code examples
xpagesxpages-ssjs

XPage SSJS validateExpression caching previous values


I have a simple user registration form which needs to check if the email address already exists - it initially works when I hit the Submit button eg if I enter an existing mail address I get the error, but if I then modify the address to a non-existent one it takes one or two more submits before passing validation. So it seems there is some caching going on somewhere.

I have an isExistingUser function in an SSJS library which simply looks up to the $Users view in the Directory and returns a boolean. Then the XPage source is as follows:

<xp:validateExpression>
 <xp:this.message><![CDATA[This user already exists!]]></xp:this.message>
 <xp:this.expression><![CDATA[#{javascript:var em = getComponent("inputEM").getValue();return isExistingUser(em)}]]> 
 </xp:this.expression>
</xp:validateExpression>

How do I force this to work correctly on every submit ie clear any previous values from memory/cache? Many thanks


Solution

  • Use getComponent(“inputEM”).getSubmittedValue() - or even better: use the data source to get the contents of inputEM such as document.getValue(“inputEM”)