我有一个使用客户端验证的 XPage。如果验证失败,它会给用户一条alert
消息,并且不允许处理服务器端的东西。我遇到的问题是无法用客户端“分配”服务器端变量。例如,考虑我有一个这样的 xp 输入字段:
<xp:inputText
styleClass="doc_field_textinput" id="input_part_title" type="text" size="40"
disableClientSideValidation="true" >
</xp:inputText>
我使用一个按钮来验证,如果验证成功 - 保存这个:
<xp:button id="save_part_btn" value="+Add this" style="float:right;">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var estdoc:NotesDocument=database.getDocumentByUNID(doc_source.getDocument().getParentDocumentUNID())
var estPartdoc:NotesDocument=estdoc.getParentDatabase().createDocument()
estPartdoc.replaceItemValue('Form','Estimate_Cost_Part')
estPartdoc.replaceItemValue('Predoc',estdoc.getUniversalID())
estPartdoc.replaceItemValue('$OSN_IsSaved','1')
estPartdoc.replaceItemValue('Title', getComponent('input_part_title').getValue())
}]]>
</xp:this.action>
<xp:this.script><![CDATA[
var result = "";
var wholeResult = true;
function isStringEmpty(string2Check)
{
return string2Check == "" || string2Check[0] == " ";
}
if(isStringEmpty(document.getElementById("#{id:input_part_title}").value))
{
wholeResult = false;
result += 'The field cannot be empty!'
}
result = result.replace(/\n$/, "")
if(!wholeResult)
{
alert(result)
}
return wholeResult;
]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
不幸的是,input_part_title
在任何情况下,服务器端的总是null,而document.getElementById("#{id:input_part_title}").value
工作得很好,并且确实按照预期的方式工作。我希望我可以将同一行代码添加到我的服务器端,但我不能,因为document
它是服务器端的未知属性。有什么方法可以以某种方式input_part_title
从客户端分配一个值吗?