我有一个表格,我正在输入一些细节,所有的细节都是重要和必要的。我使用required=true来确保它不会遗漏重要信息,但是当我点击提交按钮时,它会跳过验证阶段。
我该怎么办?
<h:panelGrid id="offline" columns="2" cellspacing="5"
cellpadding="4" style="position:relative;top:25px;left:40%;">
<p:outputLabel value="Cheque / Draft No :"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 15px;height:23px;widht:255px;'></p:outputLabel>
<p:outputLabel value="Cheque / Draft Date :"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 15px;height:23px;widht:255px;'></p:outputLabel>
<p:inputText id="number"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 13px;height:20px;widht:320px;'
value="#{Offline_Payment.chequedraftno}" required="true"
requiredMessage="Please Enter The Details">
<p:ajax process="@this" immediate="true"></p:ajax>
</p:inputText>
<p:calendar id="date"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 13px;height:20px;widht:320px;'
pattern="yyyy-MM-dd" disabledWeekends="true" navigator="true"
value="#{Offline_Payment.chequedraftdate}"
title="Please Enter the date in yyyy-MM-dd" required="true"
requiredMessage="Please Enter The Details">
</p:calendar>
<p:outputLabel value="Bank Name :"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 15px;height:23px;widht:255px;'></p:outputLabel>
<p:outputLabel value="Bank Code :"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 15px;height:23px;widht:255px;'></p:outputLabel>
<p:inputText id="banknane"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 13px;height:20px;widht:320px;'
value="#{Offline_Payment.bankname}" required="true"
requiredMessage="Please Enter The Details">
<p:ajax process="@this" immediate="true"></p:ajax>
</p:inputText>
<p:inputText
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 13px;height:20px;widht:320px;'
value="#{Offline_Payment.bankcode}" required="true"
requiredMessage="Please Enter The Required Details">
<p:ajax process="@this" immediate="true"></p:ajax>
</p:inputText>
<p:commandButton value="Cancel"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 14px;'
immediate="true"
action="/User/orderdetail.xhtml?faces-redirect=true"></p:commandButton>
<p:commandButton value="Proceed"
style='font-family: font-family : Baskerville, "Baskerville Old Face",
"Hoefler Text", Garamond, "Times New Roman", serif;;
font-size: 14px;'
action="#{Offline_Payment.offline}" update="@this,growl"
immediate="false" validateClient="true" process="@this"></p:commandButton>
</h:panelGrid>
问题是您使用了immediate="true"
属性。
查看这些链接:
- 试图理解immediate=true:跳过验证当它应该't
- JSF组件中的Immediate=true VS Immediate= false
- http://balusc.blogspot.co.at/2006/09/debug-jsf-lifecycle.html AddImmediateTrueToUIInputOnly
- http://balusc.blogspot.co.at/2006/09/debug-jsf-lifecycle.html WhenShouldIUseTheImmediateAttribute
"immediate "指定侦听器在此之前触发执行验证或从文档中填充bean,但我在这里没有看到任何动作侦听器!当你使用required,这是正确的,你的代码完全工作时,我把它放在一个但没有requiredMessage显示,我也没有看到任何影响到ajax语句,我删除了它,没有任何改变,你可以把requiredMessage在一个bean字符串为其他输出文本和清除它编程使用ajax动作,所以试着把每个在一个表单,:
<h:form>
<p:inputText
value="#{Offline_Payment.bankcode}" required="true"
requiredMessage="Please Enter The Required Details">
<p:ajax process="@this" immediate="true"></p:ajax>
</p:inputText>
</h:form>
好运。