我正在使用PrimeFaces 4.0的JSF-2.1,并尝试在下拉列表上实现部分提交,该下拉列表根据所选值填充另一个下拉列表。 ajax更改事件在第一次将ip从“select”更改为某个ip时触发并填充dstn下拉列表,但是当我第二次更改ip时,事件不会被触发。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<f:view contentType="text/html">
<h:head>
</h:head>
<h:body>
<h:form>
<p:messages id="validations" />
<h:outputLabel for="ip" value="Source:"></h:outputLabel>
<p:selectManyMenu id="ip" value="#{inputBean.ip}"
required="true" requiredMessage="Enter Source">
<f:selectItems value="#{inputBean.ipMenu}" />
<p:ajax listener="#{inputBean.populateDstn}" event="change"
update="dstn" process="@this" partialSubmit="true"/>
</p:selectManyMenu>
<h:outputLabel for="dstn" value="Destination:"></h:outputLabel>
<p:selectManyMenu id="dstn" value="#{inputBean.dstn}"
required="true" requiredMessage="Enter Destination">
<f:selectItems value="#{inputBean.dstnMenu}" />
</p:selectManyMenu>
</h:form>
</h:body>
</f:view>
</html>
支持bean
@ManagedBean
@ViewScoped
public class InputBean implements Serializable
{
private static final long serialVersionUID = 1L;
private List<Long> ip;
private Map<String, Long> ipMenu;
private List<Long> dstn;
private Map<String, Long> dstnMenu;
@ManagedProperty("#{dataBase}")
private transient DataBase db;
private StringBuilder query;
@PostConstruct
public void init()
{
ipMenu.put("Select", null);
dstnMenu.put("Select", null);
try
{
Connection connection = null;
ResultSet rs = null;
PreparedStatement pst_query = null;
query.setLength(0);
connection = db.getConnection();
query.append("SELECT DISTINCT IPADDRESS FROM ADDR ORDER BY IPADDRESS ");
pst_query = connection.prepareStatement(query.toString());
rs = pst_query.executeQuery();
while (rs.next())
{
ipMenu.put(rs.getLong("IPADDRESS")), rs.getLong("IPADDRESS"));
}
rs.close();
query.setLength(0);
pst_query.close();
connection.close();
}
catch (SQLException e)
{
e.printStackTrace();
}
}
//getters and setters
public void populateDstn()
{
System.out.println("ipaddr : " + this.ip);
try
{
dstnMenu.clear();
Connection connection = null;
ResultSet rs = null;
PreparedStatement pst_query = null;
connection = db.getConnection();
for (int i = 0; i < ip.size(); i++)
{
query.append("SELECT DISTINCT DSTN FROM ADDR " + "WHERE IPADDRESS= '" + this.ip.get(i) + "' ORDER BY DSTN ");
pst_query = connection.prepareStatement(query.toString());
rs = pst_query.executeQuery();
while (rs.next())
{
dstnMenu.put(rs.getLong("DSTN"), rs.getLong("DSTN"));
}
rs.close();
query.setLength(0);
pst_query.close();
connection.close();
}
}
catch (SQLException e)
{
FacesContext.getCurrentInstance().addMessage("tableplot:validations", new FacesMessage("Problem fetching Destinations"));
e.printStackTrace();
}
}
}
错误
Uncaught ReferenceError: cfgx is not defined primefaces.js.xhtml?ln=primefaces:1
PrimeFaces.createWidget primefaces.js.xhtml?ln=primefaces:1
PrimeFaces.cw primefaces.js.xhtml?ln=primefaces:1
(anonymous function)
(anonymous function) jquery.js.xhtml?ln=primefaces:14
bG.extend.globalEval jquery.js.xhtml?ln=primefaces:14
(anonymous function) jquery.js.xhtml?ln=primefaces:21
bG.extend.each jquery.js.xhtml?ln=primefaces:14
bG.fn.extend.domManip jquery.js.xhtml?ln=primefaces:21
bG.fn.extend.append jquery.js.xhtml?ln=primefaces:21
(anonymous function) jquery.js.xhtml?ln=primefaces:21
bG.extend.each jquery.js.xhtml?ln=primefaces:14
bG.fn.bG.each jquery.js.xhtml?ln=primefaces:14
bG.fn.extend.replaceWith jquery.js.xhtml?ln=primefaces:21
PrimeFaces.ajax.AjaxUtils.updateElement primefaces.js.xhtml?ln=primefaces:1
PrimeFaces.ajax.AjaxResponse primefaces.js.xhtml?ln=primefaces:1
(anonymous function) primefaces.js.xhtml?ln=primefaces:1
bZ jquery.js.xhtml?ln=primefaces:14
b7.fireWith jquery.js.xhtml?ln=primefaces:14
ca jquery.js.xhtml?ln=primefaces:21
bZ jquery.js.xhtml?ln=primefaces:21