我在理解这个PrimeFaces展示时遇到了一些麻烦:
password5
特别是,我不明白,为什么两个输入字段的值绑定都指向同一个属性@StrongPassword
private String password5;
。
如果我遵循此示例,但为密码强度添加一些验证
import time
print ("Welcome to balance tracker!")
sBal=float(input ("Starting balance: "))
float(sBal)
transactionAmounts = []
transactionTypes = []
print ("Your current balance is", '$',sBal)
while True:
input("Press enter to continue")
print ("""
------------
[A]ddition
[S]ubtraction
[H]istory
[I]nformation
[Q]uit
------------
""")
choice=input("What would you like to do? ")
choice = choice.upper()
if choice == "A":
aval=float(input ("Enter amount you would like to add here: "))
nBal=(sBal)+(aval)
transactionTypes.append('Addition')
transactionAmounts.append(float(aval))
balance = float(sBal) + aval
print ("Your current balance is $",balance)
elif choice == "S":
aval=input("Enter amount you would like to subtract here: ")
nBal=float(sBal)-float(aval)
transactionTypes.append('Subtraction')
transactionAmounts.append (float(aval))
balance = float(sBal) - aval
print ("Your current balance is $",balance)
elif choice == "H":
aCount = 1
tCount = 0
for i in transactionAmounts:
print ('Transaction',aCount,':',transactionTypes[tCount],i)
aCount = aCount + 1
tCount = tCount + 1
elif choice == "Q":
break
else:
print ("invalid choice")
我在这个约束上获得了重复的验证消息(对于这两个字段)。这不是预期的行为,我期待
如何实现这一目标?
答案 0 :(得分:0)
因为似乎没有必要在视图bean中记录第二个输入,所以我没有为它添加另一个属性,只是删除了值绑定:
<p:password id="pwd2" label="Password 2" required="true" />
这给出了期望的结果。第二个字段的内容也会在验证错误中保留。
答案 1 :(得分:0)
在Primefaces <p:password
组件中验证两个密码是否相等的最好方法是使用属性match
,您可以将其放在主输入密码输入表单中,并指定第二个检查输入表单的ID。 (另一个密码组件的ID,用于与Primefaces文档中的-匹配值)。
让我给你看一个例子:
<h:panelGrid columns="2" id="matchGrid" cellpadding="5">
<p:outputLabel for="usPassword" value="Password:"/>
<p:password id="usPassword" value="#{authBean.password}"
required="true" placeholder="Password"
requiredMessage="Error: enter your password"
match="usPasswordConfirm"/>
<p:outputLabel for="usPasswordConfirm" value="Repeat Password:"/>
<p:password id="usPasswordConfirm" value="#{signupBacking.password}"
required="true" placeholder="Repeat Password"
requiredMessage="Error: repeat your password"/>
</h:panelGrid>
我在这里使用match="usPasswordConfirm"
,并且相同的id值具有第二种密码输入形式,因此Primefaces将检查两个键入的值是否匹配