[英]Primefaces search mysql
I have a jsf (jsf + primefaces 4.0 ) page. 我有一个jsf(jsf + primefaces 4.0)页面。 On the page there is a inputtext element and a command button element.
在页面上有一个inputtext元素和一个command button元素。
Here is my jsf file: 这是我的jsf文件:
<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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
>
<h:head>
<title>Keresés</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
</h:head>
<ui:debug hotkey="1" />
<h:form>
<h:panelGrid columns="2">
<h:outputText value="ID:"/>
<p:inputText value="#{Kereses.id}" required="true" maxlength="20"/>
<p:commandButton id="addCategoryButton" value="Kereses" onclick="categoryDialog.show();" action="#{Kereses.selectTesztTable}"/>
</h:panelGrid>
<p:dialog id="categoryDialog" header="Category Detail" widgetVar="categoryDialog" closeOnEscape="true" resizable="false" style="width:1000px; height: 500px;" showEffect="explode" hideEffect="bounce">
<p:dataTable value="#{Kereses.values}" var="c"
styleClass="order-table" scrollable="true" scrollWidth="1500" scrollHeight="550">
<p:column style="width: 130px; text-align: center">
<f:facet name="header">OM kód:</f:facet>
<h:outputText value="#{c.omkod}" style="width: 130px; text-align: center"/>
</p:column>
</p:dataTable>
</p:dialog>
</h:form>
</html>
Here is my java code: 这是我的Java代码:
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean @SessionScoped
public class Kereses implements Serializable {
int id;
String omkod;
String URL = "jdbc:mysql://localhost:3306/osszesito?useUnicode=yes&characterEncoding=UTF-8";
String USER = "User";
String PASSWORD = "Password";
String DRIVER = "com.mysql.jdbc.Driver";
private List<Kereses> values;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getOmkod() {
return omkod;
}
public void setOmkod(String omkod) {
this.omkod = omkod;
}
public List<Kereses> getValues() throws SQLException{
values = selectTesztTable();
System.out.println("++++++++++++++++++++++++++++++++++++++++++++values erteke:" + values + "+++++++++++++++++++++++++++++++");
return values;
}
public Connection getDBConnection() {
Connection dbConnection = null;
try {
Class.forName(DRIVER);
dbConnection= DriverManager.getConnection(URL, USER, PASSWORD);
System.out.println("Connection completed.");
} catch (SQLException e) {
System.out.println(e.getMessage());
}catch(ClassNotFoundException cnfe){
cnfe.printStackTrace();
System.out.println(cnfe.getMessage());
System.exit(-1);
}
return dbConnection;
}
public List<Kereses> selectTesztTable() throws SQLException{
Kereses keres = new Kereses();
List<Kereses> lista = new ArrayList<Kereses>();
ResultSet rs = null;
PreparedStatement pst = null;
Connection con = getDBConnection();
String stmQuery = "SELECT * FROM teljes_osszesito where id like '"+ id + "'";
try {
pst = con.prepareStatement(stmQuery);
rs = pst.executeQuery();
while(rs.next()){
keres.setId(rs.getInt("id"));
keres.setOmkod(rs.getString("omkod"));
System.out.println("id: "+ getId() +" OM kód: " + getOmkod() +"---------------------vege-------------------");
}
return lista;
}catch (SQLException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}finally{
rs.close();
pst.close();
con.close();
}
return lista;
}
}
Here is my problem: 这是我的问题:
When i searching, i write id value in the inputtext and click command button. 当我搜索时,我在输入文本中输入id值,然后单击命令按钮。 But the page not found value.
但是页面没有发现价值。 If i see server.log, i see that inputtext value right and select query right, but my jsf page not display values :(
如果我看到server.log,我会看到正确的inputtext值并选择查询权,但是我的jsf页面未显示值:(
Why? 为什么?
thank you, 谢谢,
Look like you missing to update your datatable. 看起来您缺少更新数据表的机会。 So the value is inside the bean but not display.
因此,该值在bean内部,但不显示。
<h:form id="form">
<h:panelGrid columns="2">
<h:outputText value="ID:"/>
<p:inputText value="#{Kereses.id}" required="true" maxlength="20"/>
<p:commandButton id="addCategoryButton" value="Kereses" onclick="categoryDialog.show();" action="#{Kereses.selectTesztTable}" update=":form:data"/>
</h:panelGrid>
...
<p:dataTable id="data" value="#{Kereses.values}" var="c" styleClass="order-table" scrollable="true" scrollWidth="1500" scrollHeight="550">
<p:column style="width: 130px; text-align: center">
<f:facet name="header">OM kód:</f:facet>
<h:outputText value="#{c.omkod}" style="width: 130px; text-align: center"/>
</p:column>
</p:dataTable>
</h:form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.