Question

I have a jsf (jsf + primefaces 4.0 ) page. On the page there is a inputtext element and a command button element.

Here is my jsf file:

  <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:

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:

enter image description here

When i searching, i write id value in the inputtext and click command button. 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 :(

Why?

thank you,

Was it helpful?

Solution

Look like you missing to update your datatable. So the value is inside the bean but not display.

<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>                  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top