我将 JSF-2.1 与 PrimeFaces 4.0 一起使用,并尝试在下拉列表中实现部分提交,该下拉列表根据所选值填充另一个下拉列表。第一次将 ip 从“select”更改为某个 ip 并填充 dstn 下拉列表时会触发 ajax 更改事件,但是当我第二次更改 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>
支持豆
@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