2016-10-28 2 views
0

にあります。私は私のXHTMLでこのテーブルを実装:Beanメソッドからの値の表示が<table>

   <table id="tbResult" class="table table-bordered table-striped"> 
       <thead> 
       <tr> 
        <th>#{msg.Sgc001tbcod}</th> 
        <th>Browser</th> 
       </tr> 
       </thead> 

       <tfoot> 
       <tr> 
        <th>Rendering engine</th> 
        <th>Browser</th> 
       </tr> 
       </tfoot> 
       </table> 

そして、私のBEANでこの選択:私はテーブルにselect()メソッドの値を表示できるように、私はそれを作ることができますどのように

public void select(int first, int pageSize, String sortField, Object filterValue) throws SQLException, ClassNotFoundException, NamingException { 

        //System.out.println("entre al metodo SELECT"); 
        Context initContext = new InitialContext();  
        DataSource ds = (DataSource) initContext.lookup(JNDI); 
        con = ds.getConnection();  

        //Consulta paginada 
       String query = "SELECT * FROM"; 
        query += "(select query.*, rownum as rn from"; 
        query += "(SELECT A.CODIGO, A.DESCR "; 
        query += " FROM PRUEBA1 A"; 
        query += " GROUP BY A.CODIGO, A.DESCR"; 
        query += ")query) " ; 
        query += " WHERE ROWNUM <="+pageSize; 
        query += " AND rn > ("+ first +")"; 
        query += " ORDER BY " + sortField.replace("z", ""); 

       pstmt = con.prepareStatement(query); 
       //System.out.println(query); 

       r = pstmt.executeQuery(); 

       while (r.next()){ 
       Prueba select = new Prueba(); 
       select.setZcodigo(r.getString(1)); 
       select.setZdesc(r.getString(2)); 

        //Agrega la lista 
        list.add(select); 
       } 
       //Cierra las conecciones 
       pstmt.close(); 
       con.close(); 

       } 

これまでのところ、私は何らかの進歩を遂げていません。

答えて

0

最後に!!今週の研究の後、私はこのための解決策を見つけた:

コード:

<div class="box"> 
         <div class="box-header"> 
          <h3 class="box-title">Data Table With Full Features</h3> 
         </div> 
         <!-- /.box-header --> 
         <div class="box-body"> 
          <table id="tbResult" class="table table-bordered table-striped" cellspacing="0" width="100%"> 
          <thead> 
          <tr> 
           <th>#{msg.Sgc001tbcod}</th> 
           <th>#{msg.Sgc001tbdes}</th> 
          </tr> 
          </thead> 
          <tbody> 
           <c:forEach items="#{prueba.table}" varStatus="loop"> 
            <tr> 
             <td><h:outputText value="#{prueba.vltabla[loop.index][0]}" /></td> 
             <td><h:outputText value="#{prueba.vltabla[loop.index][1]}" /></td> 
            </tr>   
           </c:forEach> 
          </tbody> 
          <tfoot> 
          <tr> 
           <th>#{msg.Sgc001tbcod}</th> 
           <th>#{msg.Sgc001tbdes}</th> 
          </tr> 
          </tfoot> 
          </table> 
         </div> 
         <!-- /.box-body --> 
         </div> 

とBean:

/** 
       * Leer registros en la tabla 
       * @throws NamingException 
       * @throws IOException 
       **/ 

       private void select() throws NamingException { 

        //System.out.println("entre al metodo SELECT");  
       // ESTE SELECT SE ENCARGAR DE LLENAR EL ARREGLO VLTABLA PARA LA ETIQUETA FOREACH //  

       //Consulta paginada    
       String query = "SELECT A.CODIGO, A.DESCR "; 
        query += " FROM PRUEBA1 A"; 
        query += " GROUP BY A.CODIGO, A.DESCR"; 
        query += " ORDER BY 1"; 
       //System.out.println(query); 

       consulta.selectPntGenerica(query, JNDI);  
       inputnumber = consulta.getRows(); 
       if(inputnumber>0){ 
       vltabla = consulta.getArray(); 

        } 
       } 

のinitに()メソッドは、選択呼び出し、魔法のように動作します。

関連する問題