无法将bean方法的值显示为

时间:2016-10-28 17:25:35

标签: java oracle xhtml

我有这个问题。我在我的xhtml中实现了这个表:

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

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();

                }

我怎样才能做到这一点我可以显示表中的Select()方法的值?

到目前为止我还没有取得任何进展。

1 个答案:

答案 0 :(得分: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中调用方法select()并像魅力一样工作。