您好,我看了很多教程和帖子,但您看不到问题所在。我有一个对话框,必须将数据保存到数据库中,调用托管 bean 中的方法,但是当我调试该方法时不会触发。我的页面代码是:
<h:form>
<p:commandButton id="btnCreateCity" update=":formCreateCity" oncomplete="createCity.show()"
title="Crear nueva ciudad" value="Crear ciudad" icon="ui-icon-search"/>
</h:form>
<h:form id="formCreateCity">
<p:dialog header="Crear ciudad" widgetVar="createCity" id="dlgCreateCity"
resizable="false" modal="true" showEffect="fade" hideEffect="explode">
<!-- Alta de ciudades -->
<f:facet name="header">
<h:outputLabel value="Agregar nueva ciudad"/>
</f:facet>
<p>
<h:outputLabel for="city" value="Nombre de la ciudad:"/>
<p:inputText id="city" value="#{locationController.cityName}"/>
<p:message for="city"/>
</p>
<p>
<h:outputLabel for="postCode" value="Código Postal:"/>
<p:inputText id="postCode" value="#{locationController.postCode}"/>
<p:message for="postCode"/>
</p>
<p>
<p:selectOneMenu id="countries" value="#{locationController.selectedCountry}" required="true">
<f:selectItem itemLabel="Seleccionar uno" itemValue="" />
<f:selectItems value="#{locationController.countries}"
var="country"
itemLabel="#{country.name}"
itemValue="#{country.idCountry}"/>
</p:selectOneMenu>
</p>
<f:facet name="footer">
<p:commandButton value="Aceptar"
actionListener="#{locationController.saveCity}"
oncomplete="createCity.hide()"
icon="ui-icon-save">
<p:ajax update=":mainForm"/>
</p:commandButton>
<p:commandButton value="Cancelar" oncomplete="createCity.hide()"
icon="ui-icon-cancel"/>
</f:facet>
</p:dialog>
</h:form>
我在托管bean中的方法是:
public void saveCity(){
cityService = new CityServiceImpl();
boolean saved = cityService.save(cityName, postCode, selectedCountry);
if(saved){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("mainForm", new FacesMessage(
FacesMessage.SEVERITY_INFO, "Operación realizada",
"Se guardó la ciudad"));
}else{
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("mainForm", new FacesMessage(
FacesMessage.SEVERITY_INFO, "Operación no realizada",
"No se pudo guardar la ciudad"));
}
}
我尝试将 javax.faces.event.ActionEvent 放在方法和 nthing 的参数中。你能帮助我吗?