【发布时间】:2012-02-11 19:09:03
【问题描述】:
我在表单中有以下代码:
<p:panel id="panel" header="lalalala">
<h:panelGrid columns="5">
<h:outputLabel value="Enter name" for="name" />
<p:inputText id="name" value="#{userBean.name}"
required="true" label="name" maxlength="15"
validatorMessage="oops"
requiredMessage="ooopps">
<f:validateRegex
pattern="^somepattern$">
</f:validateRegex>
<p:ajax event="blur" update="inputValidationMessage" />
</p:inputText>
<p:message id="inputValidationMessage" showSummary="false"
for="name" />
<p:watermark for="name" value="eg. John" />
</h:panelGrid>
<p:commandButton id="submitButton" value="Submit" update="panel"
actionListener="#{userBean.save}"
onclick="handleOnclick"
oncomplete="handleAjaxResponse(xhr, status, args)">
</p:commandButton>
<p:messages autoUpdate="true" globalOnly="true" showDetail="true" />
</p:panel>
因此验证消息在inputText 元素上运行良好。但是提交按钮在单击时仍然发出 Ajax 请求,即使输入无效。如果 inputText 有效,我希望发送 Ajax 请求。
我该怎么做?
此外;还有另一种情况我想停用按钮。这是 inputText 被验证并且用户单击按钮的情况。这样做的原因是,我不希望用户错误地淹没请求。 (即反复按下提交按钮)
目前,handleOnclick javascript 函数只显示一个显示“等待”的模式对话框。由于该对话框是模态的,因此无法访问背景。但是,这仍然不能阻止用户重复按下它,因为在 onclick 和模态对话框显示之间经过了 1 秒。此外;这种方法不会阻止提交无效数据。你有什么建议?
我使用 JSF2.0 和 Primefaces 3.0。
任何帮助表示赞赏。
【问题讨论】:
标签: validation jsf jsf-2 primefaces