PrimeFaces自动完成功能无法正常工作

时间:2016-03-27 20:10:59

标签: jsf primefaces

我的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();
}

上面的方法是我的控制器类,我把它声明为@ManagedBean和@ViewScoped,我正在初始化我的服务类。 service.getConcepts(query)方法如下所示:

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;
}

CCRX1类看起来像这样:

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;
    }

}

如果你注意到,在completeConcepts方法中我有一个System.out.println()。当我开始在字段上键入内容时,它不会向控制台返回任何内容。它没有给我任何错误信息或什么都没有。我错过了什么?

我使用此链接作为指南:PrimeFaces我正在使用PrimeFaces 5.3和JSF 2.2。

0 个答案:

没有答案