我有一个密码确认组件。用户可以手动输入两个密码,也可以生成一对。生成的密码显示在选择列表中。从列表中选择密码时,应使用此密码更新两个输入密码。问题是输入密码不反映选择密码后的更改。
密码确认组件:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:outputText value="#{eval.getString(name)}: #{mandatory ? '*' : ''}"/>
<h:panelGrid columns="3">
<h:column>
<p:password id="psw1"
value="#{eval.evaluateAsBean(beanName).password}" feedback="false"
disabled="#{not enabled}" />
</h:column>
<h:column>
<p:commandButton value="#{label.create}" disabled="#{not enabled}"
action="#{eval.evaluateAsBean(beanName).generate}"
update="generated">
</p:commandButton>
</h:column>
<h:column>
<p:selectOneMenu id="generated"
disabled="#{not enabled}"
value="#{eval.evaluateAsBean(beanName).selectedPassword}">
<f:selectItems value="#{eval.evaluateAsBean(beanName).passwords}"
var="val" itemLabel="#{val}" itemValue="#{val}" />
<p:ajax listener="#{eval.evaluateAsBean(beanName).passwordChanged}"
update="psw1, psw2" />
</p:selectOneMenu>
</h:column>
<h:column>
<p:password id="psw2"
value="#{eval.evaluateAsBean(beanName).confirmedPassword}"
feedback="false" disabled="#{not enabled}" />
</h:column>
<h:column>
<h:outputText value="" />
</h:column>
<h:column>
<h:outputText value="" />
</h:column>
</h:panelGrid>
</ui:composition>
passwordChanged 监听器:
public void passwordChanged() {
this.password = selectedPassword;
this.confirmedPassword = selectedPassword;
}
编辑1
我已删除更新属性p:ajax
并将passwordChanged
侦听器更改为:
public void passwordChanged() {
this.password = selectedPassword;
this.confirmedPassword = selectedPassword;
RequestContext.getCurrentInstance().update("form:tabs:editorsGroup:editor:psw1");
RequestContext.getCurrentInstance().update("form:tabs:editorsGroup:editor:psw2");
}
使用 Firebug,psw1 的 id 是:form:tabs:9:editorsGroup:4:editor27:psw1
。还是不行。