Primefaces selectone菜单在输入之外显示数据 [英] Primefaces selectonemenu displaying data outside the input

查看:91
本文介绍了Primefaces selectone菜单在输入之外显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web编程的新手,我设法使工作成为适当的连接,因此下拉列表确实存在;我正在使用Eclipse,最新的JDK,Wildfly 10服务器,MySQL服务器5.7,Primefaces 5.3,Javax.faces 2.2.

I'm new to web programming and I manage to make work the proper connections so the dropdown DOES populate; I'm using Eclipse, latest JDK, Wildfly 10 server, MySQL server 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,我不知道发生了什么,请提出建议.

As you can see the data shows duplicated outside, there's an unexisting inputText shown and the style does look like Primefaces at all, I have no idea what is happening, please advice.

推荐答案

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

You have to replace the <head></head> tags with the jsf specific <h:head></h:head> tags to get PrimeFaces to import all necessary js and css files.

这篇关于Primefaces selectone菜单在输入之外显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆