XPage SSJS submission error?

Hi,

My SSJS is misbehaving.

Here’s a simple test case XPage with a button.

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:table>



	<xp:tr>

		<xp:td>

			<xp:label value="User i d:" id="userID_Label1" for="userID1">

			</xp:label>

		</xp:td>

		<xp:td>

			<xp:inputText id="userID1"></xp:inputText>

		</xp:td>

	</xp:tr>

</xp:table>

<xp:br></xp:br>

<xp:button value="Create Document" id="CreateDocument">

	<xp:eventHandler event="onclick" submit="true"

		refreshMode="complete">

		<xp:this.action><![CDATA[#{javascript:var db = session.getCurrentDatabase();

var doc = db.createDocument();

var compUserID = getComponent(“userID1”);

var userID = compUserID.value;

doc.replaceItemValue(“Form”, “Test”);

doc.replaceItemValue(“Username”, userID);

doc.save();

}]]></xp:this.action>

	</xp:eventHandler>

</xp:button>

</xp:view>

Presented in IE, or Firefox, the xpage sometimes works as desired. Sometimes, however, pressing the button clears the fields, and otherwise does nothing I can see. The SSJS doesn’t run, and no error is returned, or entered in the server log.

Over a short period of time, this problem occurs at regular intervals, but otherwise seems random. At present, for example, it will work for five presses, and then on the 6th it will clear the Xpage. Some of the XPages I have created have had cycles of 5-10 failed presses followed by a single success.

Why? Please help…

Subject: Back Button?

If you’re using the back button in the browser see this for an explanation…http://www.bleedyellow.com/blogs/YellowNotes/entry/xpages_data_cleared_after_4_browser_back_buttons1?lang=en

Subject: Not using back

Thanks for the suggestion, but unfortunately I’m not using the Back button.

Subject: Troubleshooting

I have no idea, but for troubleshooting purpose, you could try to change your code following my suggestions below.

  • Create a document data source instead of db.createDocument. this way you have access to more properties for the document in the “all properties” panel

  • try using something else than getCurrentDatabase(), I have seen some strange behaviour with this.

  • are you using any scoped variables, try to remove these

  • try context.reloadPage or context.redirecttopage(“sampage”) after your submit.

  • try to change the button type to Submit or Button

Thomas Adrian

http://www.notessidan.se

Subject: Thanks for the suggestions. No luck yet.

Thanks :).

Document source - I use this in some of my xpages, and it doesn’t help.

getCurrentDatabase() - again, some of the pages don’t ref the database, and they perform similarly.

Scoped variables - not using any.

context.reloadPage or context.redirecttopage(“sampage”) after your submit - thanks, I will try that.

Button type - have tried a variety, no change.