Primefaces selectonemenu 在输入之外显示数据

Primefaces selectonemenu displaying data outside the input

我是网络编程的新手,我设法建立正确的连接,因此下拉列表确实会填充;我正在使用 Eclipse,最新的 JDK,Wildfly 10 服务器,MySQL 服务器 5.7,Primefaces 5.3,Javax.faces 2.2.

这是页面:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"      
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
      >

<head>
 <title>combobox</title>
</head>
<body>


 <h:form id="form1">
  <p:panel header="Ingreso" style="width: 600px;">
   <h:panelGrid columns="2">
    <h:outputText value="Provincia: " />
    <p:selectOneMenu value="#{Usuario.provincia}" id="prov" 
                                 valueChangeListener="#{Usuario.processCant()}" >
     <f:selectItem itemLabel="Seleccione" itemValue="" />
     <f:selectItems value="#{Usuario.provincias}" /> 
     <p:ajax update="cant" event="change" />    
    </p:selectOneMenu>
    
    <h:outputText value="Cantón: " />  
                <p:selectOneMenu value="#{Usuario.canton}" id="cant" valueChangeListener="#{Usuario.processParr()}"> 
                        <f:selectItem itemLabel="Seleccione" itemValue="" />
                        <f:selectItems value="#{Usuario.cantones}"/>
                        <p:ajax update="parr" event="change" /> 
                </p:selectOneMenu>
                
                <h:outputText value="Parroquia:  " />  
                <p:selectOneMenu value="#{Usuario.parroquia}" id="parr"> 
                        <f:selectItem itemLabel="Seleccione" itemValue="" />
                        <f:selectItems value="#{Usuario.parroquias}"/>
                </p:selectOneMenu>
                    
   </h:panelGrid>
   
  </p:panel>
 </h:form>
</body>
</html>

这是 java:

@ManagedBean(name="Usuario")
@SessionScoped
public class Usuario implements Serializable {
    private static final long serialVersionUID = 1L;
    private int ID;
    private String nombre;
    private String apellido;

    private String fecha;
    private String lugar;
    private String numero;
    private String Provincia;
    private List<SelectItem> Provincias; 
    private String Canton;
    private List<SelectItem> Cantones;
    private String Parroquia;
    private List<SelectItem> Parroquias;

    public List<SelectItem> getProvincias() {
        List<SelectItem> catProvincias = new ArrayList<SelectItem>();
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schema", "root", "root");
            Statement st = con.createStatement();
            ResultSet rs = null;
            String myQuery = "SELECT Provincia FROM `schema`.provincia;"; 
            rs = st.executeQuery(myQuery);
            while (rs.next()) {
                catProvincias.add(new SelectItem(rs.getString("Provincia")));
            } 
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
        return catProvincias;
    }
    public List<SelectItem> getCantones() {
        List<SelectItem> catCantones = new ArrayList<SelectItem>();
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schema", "root", "root");
            Statement st = con.createStatement();
            ResultSet rs = null;
            String myQuery = "SELECT Canton FROM `schema`.Canton WHERE Padre=(select Provincia from `schema`.Provincia where Provincia='"+ Provincia + "')";

            rs = st.executeQuery(myQuery);
            while (rs.next()) {
                catCantones.add(new SelectItem(rs.getString("Canton")));
            } 
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
        return catCantones;
    }
    public List<SelectItem> getParroquias() {
        List<SelectItem> catParroquias = new ArrayList<SelectItem>();
        try {
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/schema", "root", "root");
            Statement st = con.createStatement();
            ResultSet rs = null;
            String myQuery = "SELECT Parroquia FROM `schema`.parroquia WHERE Padre=(select Canton from `schema`.Canton where Canton='"+ Canton +"')";
            rs = st.executeQuery(myQuery);
            while (rs.next()) {
                catParroquias.add(new SelectItem(rs.getString("Parroquia")));
            } 
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
        return catParroquias;
    }
    public void processCant() {
        getCantones();
    }
    public void processParr() {
        getParroquias();
    }

...

这是结果:

如您所见,数据显示在外部重复,显示了一个不存在的 inputText,并且样式看起来完全像 Primefaces,我不知道发生了什么,请指教。

您必须将 <head></head> 标签替换为 jsf 特定的 <h:head></h:head> 标签,以使 PrimeFaces 导入所有必要的 js 和 css 文件。