无需持久化的 Ajax 验证
大家好,
我正在尝试在我的 Seam 应用程序中设置一些验证。我可以使用它,但它有一些我想避免的副作用。我已经在输入表单上设置了字段,如下所示:
<label for="displayName" class="required">Display Name:</label>
<s:decorate id="displayNameDecorate" styleClass="errorwrapper">
<h:inputText id="displayName" value="#{presenceHome.instance.displayName}" required="true">
<a4j:support event="onblur" reRender="displayNameDecorate" ajaxSingle="true"/>
</h:inputText>
<a4j:outputPanel ajaxRendered="true">
<h:message for="displayName" styleClass="errormessage"/>
</a4j:outputPanel>
</s:decorate>
此方法工作正常。如果我输入一个被视为对显示名称无效的值,则会显示验证错误。我遇到的问题是输入的值何时有效。当我选择该字段时,a4j:support 会触发,导致数据得到验证(通过),然后保留。现在,如果在切换到下一个字段后我决定不想编辑此记录,我无法取消、恢复我的更改 - 我的更改已保存到数据库中。
无论如何,我是否可以关闭 AJAX 验证,但不会发生任何持久性?或者我只需要忘记 ajax 验证并接受它在表单提交时触发的情况。
HI all,
I'm trying to set some validation in my Seam application & I have it working but it has a few side effects I'd like to avoid. I've set up the fields on my input form like below:
<label for="displayName" class="required">Display Name:</label>
<s:decorate id="displayNameDecorate" styleClass="errorwrapper">
<h:inputText id="displayName" value="#{presenceHome.instance.displayName}" required="true">
<a4j:support event="onblur" reRender="displayNameDecorate" ajaxSingle="true"/>
</h:inputText>
<a4j:outputPanel ajaxRendered="true">
<h:message for="displayName" styleClass="errormessage"/>
</a4j:outputPanel>
</s:decorate>
This method works fine. If I enter a value that is considered invalid for display name, then it shows a validation error. The trouble I have is when the value entered is valid. When I tab out the field, the a4j:support fires off causing the data to be validated (which passes) and then persisted. Now if after tabbing into the next field I decide that I didn't want to edit this record, I can't cancel out, reverting my changes - my changes have already been persisted to the DB.
Is there anyway I can have the AJAX validation fire off but without any persistence occurring? Or do I just need to forget about the ajax validation and live with it firing off on form submit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您所显示的代码中发生了什么,但会使用 Richfaces 的 < rich:ajaxValidator > 不会让生活变得更轻松吗?文档页面位于此处
I'm not sure what's happening in the code you're showing, but would using something like Richfaces' < rich:ajaxValidator > not make life easier? The doc page is here