我在模态中有一个表单,仅在单击两次时才调用命令按钮。我在Chrome DevTools中进行了查看,并且在第一次单击时,发送了表单,但是什么也没有发生,当再次单击时,我的信息就会更新。
我已经在Google堆栈上搜索了,但无法解决。
<div class="row">
<div class="col-md-12" style="left: auto">
<p:dialog header="Editar Contato" widgetVar="editContact" modal="true" width="50%">
<h:form id="formEditContactModal">
<div>
<div class="form-group">
<label>Informe o novo nome do contato: <a style="color:red">*</a></label>
<h:inputText id="inputStrEditName" class="form-control" value="#{BeanManageContact.strName}"/>
</div>
</div>
<div>
<h:commandButton value="Salvar edição"
class="btn btn-primary"
style="margin-top: 15px; float: right; margin-left: 15px;"
actionListener="#{BeanManageContact.executeUpdate()}">
<f:ajax execute="@form"/>
</h:commandButton>
<h:commandButton value="Voltar"
class="btn btn-default"
style="margin-top: 15px; float: right; margin-right: 15px;"
onclick="PF('editContact').hide();"
/>
</div>
</h:form>
</p:dialog>
</div>
</div>
我的豆子
public void executeUpdate(){
System.out.println("entrando no metodo execute update");
PojoUser pu = new PojoUser();
pu.setId((Long) session.getAttribute("USER_SECURITY_LOGIN_ID"));
PojoContact tmpPc = new PojoContact();
tmpPc.setId(lonId);
System.out.println("ID EXECUTE UPDATE: " + lonId);
tmpPc.setStrToName(strName);
System.out.println("NOME EXECUTE UPDATE: " + strName);
tmpPc.setStrPhone1(strPhone1);
System.out.println("PHONE EXECUTE UPDATE: " + strPhone1);
tmpPc.setStrPhone2(strPhone2);
tmpPc.setStrEmail1(strEmail1);
System.out.println("EMAIL EXECUTE UPDATE: " + strEmail1);
tmpPc.setStrEmail2(strEmail2);
if (listContactToGroup != null || listContactToGroup.size() == 0) {
for (PojoContactToGroup tmpPctg : listContactToGroup) {
dg.saveSes(tmpPctg);
continue;
}
originalListContactToGroup = dmc.searchGroupPerUser(pu, lastContact.getId());
}
if (listContactToGroup != null || listContactToGroup.size() == 0) {
for (PojoContactToGroup tmpPctg : originalListContactToGroup) {
if (!listContactToGroup.stream().anyMatch(t -> t.getPojoGroup().getId().equals(tmpPctg.getPojoGroup().getId()))) {
dmc.deleteGroupFromContact(tmpPctg, pu);
} else {
dg.saveSes(tmpPctg);
}
}
}
RequestContext.getCurrentInstance().execute("PF('editContact').hide();");
if (dmc.updateContact(tmpPc, pu)) {
showEditContact = false;
showButtonUpdate = false;
statusMessage = "Contato atualizado com sucesso!";
strName = null;
strPhone1 = null;
strPhone2 = null;
strEmail1 = null;
strEmail2 = null;
} else {
statusMessage = " Falha ao tentar atualizar o cliente!";
updateEntirePage("formInfo");
showStatusMessage = true;
updateEntirePage("statusMessage");
}
}