Jsf PrimeFaces自动完成不工作

Jsf PrimeFaces自动完成不工作,jsf,primefaces,Jsf,Primefaces,我的xhtml中有以下内容: <p:outputLabel for="concept" value="Concept" /> <p:autoComplete id="concept" value="#{cCRX1Controller.ccrx1.tbcodigo}" completeMethod="#{cCRX1Controller.completeConcepts}" var="concept"

我的xhtml中有以下内容:

<p:outputLabel for="concept" value="Concept" />
        <p:autoComplete id="concept"
            value="#{cCRX1Controller.ccrx1.tbcodigo}"
            completeMethod="#{cCRX1Controller.completeConcepts}" var="concept"
            itemLabel="#{concept.tbdesc}" itemValue="#{concept.tbcodigo}"
            requiredMessage="You must select a concept."
            required="#{request.getParameter('validate')}" />

completeConcepts方法如下所示:

public ArrayList<CCRX1> completeConcepts(String query)
{
    ccrx1.setConcepts(service.getConcepts(query));

    System.out.println(query);

    return ccrx1.getConcepts();
}
public ArrayList<CCRX1> getConcepts(String query)
{
    String sqlConcepts = "SELECT TBCODIGO, TBDESC, TBIOE FROM CCRX1 WHERE STATUS <> 'I' "
            + "AND QOFICINA IN ('', ?) AND TBDESC LIKE '%?%'";

    ArrayList<CCRX1> listC = new ArrayList<CCRX1>();

    try {
        conn = ConnectionDB.getDS().getConnection();

        prstmt = conn.prepareStatement(sqlConcepts);

        prstmt.setString(1, "0101");

        prstmt.setString(2, query);

        rs = prstmt.executeQuery();

        // setting the data from CCRX1
        while (rs.next()) {

            CCRX1 c = new CCRX1();

            c.setTbcodigo(rs.getString("TBCODIGO"));

            c.setTbdesc(rs.getString("TBDESC"));

            c.setTbioe(rs.getString("TBIOE"));

            listC.add(c);

        }

        // close resources
        prstmt.close();

        rs.close();

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            prstmt.close();

            rs.close();

            conn.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    return listC;
}
public class CCRX1 {

    private String tbcodigo;

    private String tbdesc;

    private String tbioe;

    private String tbqcon;

    private List<CCRX1> concepts = new ArrayList<CCRX1>();

    public String getTbcodigo() {
        return tbcodigo;
    }

    public void setTbcodigo(String tbcodigo) {
        if (tbcodigo == null)
            this.tbcodigo = tbcodigo;

        else
            this.tbcodigo = tbcodigo.trim();
    }

    public String getTbdesc() {
        return tbdesc;
    }

    public void setTbdesc(String tbdesc) {
        if (tbdesc == null)
            this.tbdesc = tbdesc;

        else
            this.tbdesc = tbdesc.trim();
    }

    public String getTbioe() {
        return tbioe;
    }

    public void setTbioe(String tbioe) {
        if (tbioe == null)
            this.tbioe = tbioe;

        else
            this.tbioe = tbioe.trim();
    }

    public List<CCRX1> getConcepts() {
        return concepts;
    }

    public void setConcepts(List<CCRX1> concepts) {
        this.concepts = concepts;
    }

    public String getTbqcon() {
        return tbqcon;
    }

    public void setTbqcon(String tbqcon) {
        this.tbqcon = tbqcon;
    }

    @Override
    public String toString() {
        return tbcodigo;
    }

}
public ArrayList completeConcepts(字符串查询)
{
ccrx1.setConcepts(service.getConcepts(query));
System.out.println(查询);
返回ccrx1.getConcepts();
}
上面的方法是我的控制器类,我将它声明为@ManagedBean和@ViewScoped,我正在初始化我的服务类。service.getConcepts(查询)方法如下所示:

public ArrayList<CCRX1> completeConcepts(String query)
{
    ccrx1.setConcepts(service.getConcepts(query));

    System.out.println(query);

    return ccrx1.getConcepts();
}
public ArrayList<CCRX1> getConcepts(String query)
{
    String sqlConcepts = "SELECT TBCODIGO, TBDESC, TBIOE FROM CCRX1 WHERE STATUS <> 'I' "
            + "AND QOFICINA IN ('', ?) AND TBDESC LIKE '%?%'";

    ArrayList<CCRX1> listC = new ArrayList<CCRX1>();

    try {
        conn = ConnectionDB.getDS().getConnection();

        prstmt = conn.prepareStatement(sqlConcepts);

        prstmt.setString(1, "0101");

        prstmt.setString(2, query);

        rs = prstmt.executeQuery();

        // setting the data from CCRX1
        while (rs.next()) {

            CCRX1 c = new CCRX1();

            c.setTbcodigo(rs.getString("TBCODIGO"));

            c.setTbdesc(rs.getString("TBDESC"));

            c.setTbioe(rs.getString("TBIOE"));

            listC.add(c);

        }

        // close resources
        prstmt.close();

        rs.close();

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            prstmt.close();

            rs.close();

            conn.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    return listC;
}
public class CCRX1 {

    private String tbcodigo;

    private String tbdesc;

    private String tbioe;

    private String tbqcon;

    private List<CCRX1> concepts = new ArrayList<CCRX1>();

    public String getTbcodigo() {
        return tbcodigo;
    }

    public void setTbcodigo(String tbcodigo) {
        if (tbcodigo == null)
            this.tbcodigo = tbcodigo;

        else
            this.tbcodigo = tbcodigo.trim();
    }

    public String getTbdesc() {
        return tbdesc;
    }

    public void setTbdesc(String tbdesc) {
        if (tbdesc == null)
            this.tbdesc = tbdesc;

        else
            this.tbdesc = tbdesc.trim();
    }

    public String getTbioe() {
        return tbioe;
    }

    public void setTbioe(String tbioe) {
        if (tbioe == null)
            this.tbioe = tbioe;

        else
            this.tbioe = tbioe.trim();
    }

    public List<CCRX1> getConcepts() {
        return concepts;
    }

    public void setConcepts(List<CCRX1> concepts) {
        this.concepts = concepts;
    }

    public String getTbqcon() {
        return tbqcon;
    }

    public void setTbqcon(String tbqcon) {
        this.tbqcon = tbqcon;
    }

    @Override
    public String toString() {
        return tbcodigo;
    }

}
public ArrayList getConcepts(字符串查询)
{
String sqlConcepts=“从CCRX1中选择TBCODIGO、TBDESC、TBIOE,其中状态为“I”
+以及(“”、“”)中的QOFICINA和类似于“%”的TBDESC;
ArrayList listC=新的ArrayList();
试一试{
conn=ConnectionDB.getDS().getConnection();
prstmt=conn.prepareStatement(sqlConcepts);
prstmt.setString(1,“0101”);
prstmt.setString(2,查询);
rs=prstmt.executeQuery();
//从CCRX1设置数据
while(rs.next()){
CCRX1 c=新的CCRX1();
c、 setTbcodigo(rs.getString(“TBCODIGO”);
c、 setTbdesc(rs.getString(“TBDESC”));
c、 setTbioe(rs.getString(“TBIOE”);
增加(c);
}
//密切资源
prstmt.close();
rs.close();
}捕获(SQLE异常){
e、 printStackTrace();
}最后{
试一试{
prstmt.close();
rs.close();
康涅狄格州关闭();
}catch(SQLException-ex){
例如printStackTrace();
}
}
返回listC;
}
CCRX1类如下所示:

public ArrayList<CCRX1> completeConcepts(String query)
{
    ccrx1.setConcepts(service.getConcepts(query));

    System.out.println(query);

    return ccrx1.getConcepts();
}
public ArrayList<CCRX1> getConcepts(String query)
{
    String sqlConcepts = "SELECT TBCODIGO, TBDESC, TBIOE FROM CCRX1 WHERE STATUS <> 'I' "
            + "AND QOFICINA IN ('', ?) AND TBDESC LIKE '%?%'";

    ArrayList<CCRX1> listC = new ArrayList<CCRX1>();

    try {
        conn = ConnectionDB.getDS().getConnection();

        prstmt = conn.prepareStatement(sqlConcepts);

        prstmt.setString(1, "0101");

        prstmt.setString(2, query);

        rs = prstmt.executeQuery();

        // setting the data from CCRX1
        while (rs.next()) {

            CCRX1 c = new CCRX1();

            c.setTbcodigo(rs.getString("TBCODIGO"));

            c.setTbdesc(rs.getString("TBDESC"));

            c.setTbioe(rs.getString("TBIOE"));

            listC.add(c);

        }

        // close resources
        prstmt.close();

        rs.close();

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            prstmt.close();

            rs.close();

            conn.close();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    return listC;
}
public class CCRX1 {

    private String tbcodigo;

    private String tbdesc;

    private String tbioe;

    private String tbqcon;

    private List<CCRX1> concepts = new ArrayList<CCRX1>();

    public String getTbcodigo() {
        return tbcodigo;
    }

    public void setTbcodigo(String tbcodigo) {
        if (tbcodigo == null)
            this.tbcodigo = tbcodigo;

        else
            this.tbcodigo = tbcodigo.trim();
    }

    public String getTbdesc() {
        return tbdesc;
    }

    public void setTbdesc(String tbdesc) {
        if (tbdesc == null)
            this.tbdesc = tbdesc;

        else
            this.tbdesc = tbdesc.trim();
    }

    public String getTbioe() {
        return tbioe;
    }

    public void setTbioe(String tbioe) {
        if (tbioe == null)
            this.tbioe = tbioe;

        else
            this.tbioe = tbioe.trim();
    }

    public List<CCRX1> getConcepts() {
        return concepts;
    }

    public void setConcepts(List<CCRX1> concepts) {
        this.concepts = concepts;
    }

    public String getTbqcon() {
        return tbqcon;
    }

    public void setTbqcon(String tbqcon) {
        this.tbqcon = tbqcon;
    }

    @Override
    public String toString() {
        return tbcodigo;
    }

}
公共类CCRX1{
私有字符串tbcodigo;
私有字符串tbdesc;
私有字符串tbioe;
专用字符串tbqcon;
私有列表概念=新的ArrayList();
公共字符串getTbcodigo(){
返回tbcodigo;
}
公共无效setTbcodigo(字符串tbcodigo){
if(tbcodigo==null)
this.tbcodigo=tbcodigo;
其他的
this.tbcodigo=tbcodigo.trim();
}
公共字符串getTbdesc(){
返回tbdesc;
}
公共无效设置tbdesc(字符串tbdesc){
如果(tbdesc==null)
this.tbdesc=tbdesc;
其他的
this.tbdesc=tbdesc.trim();
}
公共字符串getBeoE(){
返回tbioe;
}
公共无效设置tbioe(字符串tbioe){
如果(tbioe==null)
this.tbioe=tbioe;
其他的
this.tbioe=tbioe.trim();
}
公共列表getConcepts(){
回归概念;
}
公共概念(列出概念){
这个概念=概念;
}
公共字符串getTbqcon(){
返回tbqcon;
}
公共无效设置tbqcon(字符串tbqcon){
this.tbqcon=tbqcon;
}
@凌驾
公共字符串toString(){
返回tbcodigo;
}
}
如果您注意到,在completeConcepts方法中,我有一个System.out.println()。当我开始在字段中输入内容时,它不会将任何内容返回到控制台。它没有给我任何错误信息或什么都没有。我错过了什么


我使用这个链接作为指导:我使用的是PrimeFaces 5.3和JSF 2.2。

我可以看到这里您没有使用转换器,但这就是为什么我甚至不能在控制台中显示从@AliHelmy表单传递的查询参数?我没有看到您将itemValue用作字符串而不是对象。对不起,你能把complete方法的返回类型改为
List
not
ArrayList
吗?我试过了,但这不是我在这里看到的问题,你没有使用转换器,但这就是为什么我甚至不能在控制台中显示从@AliHelmy表单传递的查询参数?我没有看到你正在使用itemValue作为字符串不是一个物体。对不起,你能把complete方法的返回类型改为
List
not
ArrayList
吗?我试过了,这不是问题所在