嗨在我的应用程序中,我在当前地址和另一个永久地址中有两个块。
如果我目前的地址和永久地址相同,我需要将当前地址字段复制到永久地址字段。
我在这里附上了代码
<h:outputText value="#{msg['elicense.examinationform.address.presentaddressline1']}" />
<p:inputText id="presentaddress1" value="#{personalBean.presentAddressLine1}" label="Present Address Line1" />
<p:watermark for="presentaddress1" value="Present Address Line1" id="presentaddressdata1"></p:watermark>
<h:outputText value="#{msg['elicense.examinationform.address.copy']}" />
<p:selectBooleanCheckbox value="#{examinationFormBean.copyAddress}" label="addresscopy" />
<p:spacer></p:spacer>
<h:outputText value="#{msg['elicense.examinationform.address.permanentline1']}" />
<p:inputText id="address1" value="#{personalBean.permanentAddressLine1}" label="Permanent Address Line1" />
我已更新了我的代码。当我使用p:ajax选中复选框时,我需要将presentAddressLine1值复制到permanentAddressLine1。请帮帮我
答案 0 :(得分:1)
这是在点击p:selectBooleanCheckBox
组件时发送Ajax请求的问题。在这里你有一个基本的SSCCE:
@ManagedBean
@ViewScoped
public class Bean implements Serializable {
private String address1;
private String address2;
private boolean copyAdress;
public String getAddress1() {
return address1;
}
public String getAddress2() {
return address2;
}
public boolean isCopyAdress() {
return copyAdress;
}
public void listener() {
if (copyAdress) {
address2 = address1;
} else {
address2 = "";
}
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public void setCopyAdress(boolean copyAdress) {
this.copyAdress = copyAdress;
}
}
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head />
<h:body>
<h:form>
<p:inputText value="#{bean.address1}" />
<p:inputText id="add2" value="#{bean.address2}" />
<p:selectBooleanCheckbox value="#{bean.copyAdress}">
<p:ajax listener="#{bean.listener}" update="add2" process="@form" />
</p:selectBooleanCheckbox>
</h:form>
</h:body>
</html>
p:ajax
指定一个侦听器,其中包含我们要在服务器端调用的方法。我们将整个表单发送到进程(这样地址的当前值在执行侦听器之前设置)和请求之后要更新的组件必须是附加到第二个地址的输入,这是我们想要的将值复制到。