There's two variants of NotesXSPDocument.getDocument().
One with no parameters, as in your code example, and one with a boolean flag, applyChanges. Try using document.getDocument( true )
http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/XPagesExtAPI/8.5.2/com/ibm/xsp/model/domino/wrapped/DominoDocument.html#getDocument(boolean)