Primefaces selectonemenu显示输入之外的数据

时间:2016-04-24 23:11:08

标签: jsf primefaces selectonemenu

我是网络编程的新手,我设法使工作成为正确的连接,因此下拉列表会填充;我正在使用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();
    }

...

这就是结果: result

正如你可以看到数据显示重复的外部,显示了一个未显示的inputText,样式看起来像Primefaces,我不知道发生了什么,请建议。

1 个答案:

答案 0 :(得分:1)

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