我一直在努力解决一个问题,我找不到解决它的方法,我在网上找不到任何相关的东西。
我正在使用带有 Primefaces 的 Netbeans 来开发 JSF Web 应用程序。
一切正常,除了有时对动作侦听器的调用被多次执行。
例如,这是我的带有 primefaces 的 JSF 页面:
<h:body>
<ui:composition template="home.xhtml">
<ui:define name="content">
<h2>Administración de alertas SMS</h2>
<p:panel id="display">
<p:selectBooleanCheckbox itemLabel="Enviar alertas SMS" value="#{smsConfigBean.alertsEnabled}"/>
<p>
<h:outputText value="Mensaje de Texto: " /><br /><br />
<p:inputTextarea rows="5" cols="50" counterTemplate="{0} caracteres restantes." counter="counter" maxlength="160" value="#{smsConfigBean.smsMessage}" id="smsMessage"/>
<br />
<h:outputText id="counter" />
</p>
<p>
<h:outputText value="Dispositivo de envio SMS: " />
<p:selectOneRadio id="options" value="#{smsConfigBean.usePhone}">
<f:selectItem itemLabel="Modem USB" itemValue="false" />
<f:selectItem itemLabel="Telefono Android" itemValue="true" />
</p:selectOneRadio>
</p>
<br />
<p:tabView id="tabView">
<p:tab id="tab1" title="Modem USB">
<h:panelGrid id="modemGrid" columns="2" cellpadding="4">
<h:outputText value="Puerto: " />
<p:inputText id="port" value="#{smsConfigBean.port}"/>
<h:outputText value="Bit Rate (Opcional): " />
<p:inputText id="bitRate" value="#{smsConfigBean.bitRate}"/>
<h:outputText value="Nombre de modem (Opcional): " />
<p:inputText id="modemName" value="#{smsConfigBean.modemName}"/>
<h:outputText value="PIN: " />
<p:inputText id="pin" value="#{smsConfigBean.modemPin}"/>
<h:outputText value="Centro de Mensajes: " />
<p:inputText id="smsc" value="#{smsConfigBean.SMSC}"/>
</h:panelGrid>
</p:tab>
<p:tab id="tab2" title="Telefono Android">
<h:panelGrid id="phoneGrid" columns="2" cellpadding="4">
<h:outputText value="Path ADB:" />
<p:inputText id="adbPath" value="#{smsConfigBean.adbPath}"/>
<h:outputText value="Directorio de Configuracion:" />
<p:inputText id="configPath" value="#{smsConfigBean.configPath}"/>
<h:outputText value="Modo de conexion " />
<p:selectOneRadio id="connectOptions" value="#{smsConfigBean.useWifi}">
<f:selectItem itemLabel="USB" itemValue="false"/>
<f:selectItem itemLabel="WiFi" itemValue="true" />
</p:selectOneRadio>
<h:outputText value="Direccion IP (Solo para WiFi): " />
<p:inputText id="ipDir" value="#{smsConfigBean.ipDir}"/>
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
<br />
<p:commandButton id="saveSmsAlerts" value="Guardar" update="messages" action="#{smsConfigBean.saveChanges}" actionListener="#{smsConfigBean.saveChanges}"/>
</ui:define>
</ui:composition>
</h:body>
这是我的后端 bean:
包装豆类;
导入 helpers.Global;导入 javax.faces.bean.ManagedBean;导入 javax.faces.bean.SessionScoped;
@ManagedBean @SessionScoped 公共类 SmsConfigBean {
private Boolean alertsEnabled; private Boolean usePhone; private Boolean useWifi; private String port; private int bitRate; private String modemName; private String modemPin; private String SMSC; private String adbPath; private String configPath; private String ipDir; private String smsMessage; public SmsConfigBean() { alertsEnabled = Global.getAlertsEnabled(); port = Global.getPort(); bitRate = Global.getBitRate(); modemName = Global.getModemName(); modemPin = Global.getModemPin(); SMSC = Global.getSMSC(); usePhone = Global.getUsePhone(); adbPath = Global.getAdbPath(); configPath = Global.getConfigPath(); useWifi = Global.getUseWifi(); ipDir = Global.getIpDir(); smsMessage = Global.getSmsMessage(); } public Boolean getAlertsEnabled() { return alertsEnabled; } public void setAlertsEnabled(Boolean alertsEnabled) { this.alertsEnabled = alertsEnabled; } public String getPort() { return port; } public void setPort(String port) { this.port = port; } public int getBitRate() { return bitRate; } public void setBitRate(int bitRate) { this.bitRate = bitRate; } public String getModemName() { return modemName; } public void setModemName(String modemName) { this.modemName = modemName; } public String getModemPin() { return modemPin; } public void setModemPin(String modemPin) { this.modemPin = modemPin; } public String getSMSC() { return SMSC; } public void setSMSC(String SMSC) { this.SMSC = SMSC; } public Boolean getUsePhone() { return usePhone; } public void setUsePhone(Boolean usePhone) { this.usePhone = usePhone; } public String getAdbPath() { return adbPath; } public void setAdbPath(String adbPath) { this.adbPath = adbPath; } public String getConfigPath() { return configPath; } public void setConfigPath(String configPath) { this.configPath = configPath; } public Boolean getUseWifi() { return useWifi; } public void setUseWifi(Boolean useWifi) { this.useWifi = useWifi; } public String getIpDir() { return ipDir; } public void setIpDir(String ipDir) { this.ipDir = ipDir; } public String getSmsMessage() { return smsMessage; } public void setSmsMessage(String smsMessage) { this.smsMessage = smsMessage; } public void saveChanges(){ Global.setSmsMessage(smsMessage); Global.setIpDir(ipDir); Global.setUseWifi(useWifi); Global.setConfigPath(configPath); Global.setAdbPath(adbPath); Global.setUsePhone(usePhone); Global.setSMSC(SMSC); Global.setModemPin(modemPin); Global.setModemName(modemName); Global.setBitRate(bitRate); Global.setPort(port); Global.setAlertsEnabled(alertsEnabled); Global.sendInfoResponseMessage("Cambios guardados con exito"); }
}
问题是,当通过点击命令按钮“saveSmsAlerts”保存此表单的更改时,调用会进行两次。导致咆哮消息也显示两次。(您不会看到咆哮组件,因为它是在模板中定义的)
这也发生在我为使用 fileuploader 上传文件的同一应用程序所做的另一个页面中。文件上传4次!!
我正在使用 chrome 来测试应用程序和 netbeans 来开发它。