1
votes

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

1
Try getComponent(“inputEM”).getSubmittedValue() - or even better: use the data source to get the contents of inputEM such as document.getValue(“inputEM”) - Per Henrik Lausten
Thank you so much for your response Henrik - the change to getSubmittedValue() works perfectly every time now. I can't say I understand why exactly but really appreciate your answer! It has saved me a lot of time. - crispy235
Great to hear. I have added it as an answer that you can accept. - Per Henrik Lausten
"I can't say I understand why exactly" - get familiar with JSF cycle - in validation phase submitted values are not updated in the model yet. - Frantisek Kossuth

1 Answers

0
votes

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