Paginaçao Tabela Visual Web JSF do NetBeans

0 respostas
raphaelguitarra

Ola pessoal.Estou trabalhando num projeto javaEE usando o netbeans 6.5 e suas ferramentas , expecialmente a tabela.Estou com o projeto pronto e funcionando, porem, a tabela so pagina quando eu aperto no botao buscar, que tem a missao apenas de buscar e formar a query baseado na seleçao dos combo-boxes selecionados.Gostaria de saber se alguem sabe o porque da paginaçao so funcionar quando aperto o botao buscar....

eis o codigo JSP :
<?xml version="1.0" encoding="UTF-8"?>
<!-- 
    Document   : BuscaDados2
    Created on : 08/07/2009, 23:58:02
    Author     : Michel
-->
<jsp:root version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
    <jsp:directive.page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"/>
    <f:view>
        <webuijsf:page id="page1">
            <webuijsf:html id="html1">
                <webuijsf:head id="head1">
                    <webuijsf:link id="link1" url="/resources/stylesheet.css"/>
                </webuijsf:head>
                <webuijsf:body focus="form1:dropDown1" id="body1" style="-rave-layout: grid">
                    <webuijsf:form id="form1" virtualFormsConfig="form1 | |">
                        <webuijsf:image id="image1" style="left: 48px; top: 0px; position: absolute" url="/resources/busms.jpg"/>
                        <webuijsf:table binding="#{BuscaDados.table1}" id="table1" paginateButton="true" paginationControls="true"
                            style="left: 96px; top: 216px; position: absolute; width: 0px" title="Busms Web Interface" width="0">
                            <webuijsf:tableRowGroup id="tableRowGroup1" rows="5" sourceData="#{BuscaDados.paradasOnibusPOJO}" sourceVar="currentRow">
                                <webuijsf:tableColumn headerText="name" id="tableColumn1" sort="name">
                                    <webuijsf:staticText id="staticText1" text="#{currentRow.value['name']}"/>
                                </webuijsf:tableColumn>
                                <webuijsf:tableColumn headerText="timeDate" id="tableColumn2" sort="timeDate">
                                    <webuijsf:staticText id="staticText2" text="#{currentRow.value['timeDate']}"/>
                                </webuijsf:tableColumn>
                            </webuijsf:tableRowGroup>
                        </webuijsf:table>
                        <webuijsf:dropDown binding="#{BuscaDados.dropDown1}" id="dropDown1" items="#{BuscaDados.redePOJO}" onChange=""
                            selected="#{BuscaDados.idRede}" style="height: 24px; left: 144px; top: 144px; position: absolute; z-index: 501"
                            validatorExpression="#{BuscaDados.dropDown1_validate}" valueChangeListenerExpression="#{BuscaDados.dropDownRede}" width="120"/>
                        <webuijsf:dropDown binding="#{BuscaDados.dropDown2}" id="dropDown2" items="#{BuscaDados.rotaPOJO}" onChange=""
                            selected="#{BuscaDados.idRota}" style="height: 24px; left: 144px; top: 168px; position: absolute; z-index: 502"
                            validatorExpression="#{BuscaDados.dropDown2_validate}" valueChangeListenerExpression="#{BuscaDados.dropDownRota}" width="120"/>
                        <webuijsf:dropDown binding="#{BuscaDados.dropDown3}" id="dropDown3" items="#{BuscaDados.veiculoPOJO}" onChange=""
                            selected="#{BuscaDados.idVeiculo}" style="height: 24px; left: 456px; top: 144px; position: absolute; z-index: 503"
                            validatorExpression="#{BuscaDados.dropDown3_validate}" valueChangeListenerExpression="#{BuscaDados.dropDownVeiculo}" width="120"/>
                        <webuijsf:dropDown binding="#{BuscaDados.dropDown4}" id="dropDown4" items="#{BuscaDados.periodoEtaPOJO}" onChange=""
                            style="height: 24px; left: 456px; top: 168px; position: absolute; z-index: 503"
                            valueChangeListenerExpression="#{BuscaDados.dropDownPeriodoEta}" width="120"/>
                        <webuijsf:staticText id="staticText3"
                            style="color: rgb(255, 0, 51); height: 24px; left: 96px; top: 120px; position: absolute; width: 144px" text="Selecione"/>
                        <webuijsf:staticText id="staticText4" style="height: 24px; left: 96px; top: 144px; position: absolute; width: 120px; z-index: 500" text="Malha"/>
                        <webuijsf:staticText id="staticText5" style="height: 24px; left: 72px; top: 168px; position: absolute; width: 96px; z-index: 500" text="Linha - Direção"/>
                        <webuijsf:staticText id="staticText6" style="height: 24px; left: 384px; top: 168px; position: absolute; width: 96px" text="Período            ETA       "/>
                        <webuijsf:staticText id="staticText7" style="height: 24px; left: 384px; top: 144px; position: absolute; width: 96px" text="Veiculo ID"/>
                        <webuijsf:button actionExpression="#{BuscaDados.button1_action}" binding="#{BuscaDados.button1}" id="button1"
                            style="left: 599px; top: 216px; position: absolute" text="Botão"/>
                    </webuijsf:form>
                </webuijsf:body>
            </webuijsf:html>
        </webuijsf:page>
    </f:view>
</jsp:root>
e o codigo Java :
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package busmsweb;

import busms.inteldev.com.main.Rede;
import busms.inteldev.com.exception.BusmsException;
import busms.inteldev.com.main.ParadaOnibus;
import busms.inteldev.com.main.PeriodoEta;
import busms.inteldev.com.main.Rota;
import busms.inteldev.com.main.Usuario;
import busms.inteldev.com.main.Veiculo;
import busms.inteldev.com.pojo.ParadaOnibusPOJO;
import busms.inteldev.com.pojo.PeriodoEtaPOJO;
import busms.inteldev.com.pojo.RedePOJO;
import busms.inteldev.com.pojo.RotaPOJO;
import busms.inteldev.com.pojo.UsuarioPOJO;
import busms.inteldev.com.pojo.VeiculoPOJO;
import com.sun.rave.faces.data.DefaultTableDataModel;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import com.sun.webui.jsf.component.Button;
import com.sun.webui.jsf.component.DropDown;
import com.sun.webui.jsf.component.Page;
import com.sun.webui.jsf.component.Table;
import com.sun.webui.jsf.component.TableRowGroup;
import java.util.ArrayList;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.swing.JOptionPane;



/**
 * <p>Page bean that corresponds to a similarly named JSP page.  This
 * class contains component definitions (and initialization code) for
 * all components that you have defined on this page, as well as
 * lifecycle methods and event handlers where you may add behavior
 * to respond to incoming events.</p>
 *
 * @version BuscaDados2.java
 * @version Created on 08/07/2009, 23:58:02
 * @author Michel
 */

public class BuscaDados extends AbstractPageBean {
    // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

    /**
     * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
     * This method is automatically generated, so any user-specified code inserted
     * here is subject to being replaced.</p>
     */


    private Page page1 = new Page();

    public Page getPage1() {
        return page1;
    }

    public void setPage1(Page p) {
        this.page1 = p;
    }


    private void  _init() throws BusmsException {
        table1.setStyle("left: 0px; top: 240px; position: absolute; width: 100%");

  }
    // </editor-fold>

    private VeiculoPOJO[] veiculoPOJO = null;
    //private ParadaOnibusPOJO[] paradasOnibusPOJO = null;
    private ArrayList paradasOnibusPOJO = null;
    private RedePOJO[] redePOJO = null;
    private RotaPOJO[] rotaPOJO = null;
    private UsuarioPOJO[] usuarioPOJO = null;
    private PeriodoEtaPOJO[] periodoEtaPOJO = null;
    //Dados membros Dropdownlists
    private String idRede = null;
    private String idRota = null;
    private String idPeriodoEta = null;
    private String idVeiculo = null;
    private String novaPagina;

    /*
    private DropDown dropDownRota = new DropDown();
    private DropDown dropDownVeiculo = new DropDown();
    private DropDown dropDownPeriodoEta = new DropDown();
*/
    //get set Dados membros Dropdownlists
    public String getIdPeriodoEta() {
        return idPeriodoEta;
    }

    public void setIdPeriodoEta(String idPeriodoEta) {
        this.idPeriodoEta = idPeriodoEta;
    }

    public String getIdRede() {
        return idRede;
    }

    public void setIdRede(String idRede) {
        this.idRede = idRede;
    }

    public String getIdRota() {
        return idRota;
    }

    public void setIdRota(String idRota) {
        this.idRota = idRota;
    }

    public String getIdVeiculo() {
        return idVeiculo;
    }

    public void setIdVeiculo(String idVeiculo) {
        this.idVeiculo = idVeiculo;
    }

    public UsuarioPOJO[] getUsuarioPOJO() {
        return usuarioPOJO;
    }

    public void setUsuarioPOJO(UsuarioPOJO[] usuarioPOJO) {
        this.usuarioPOJO = usuarioPOJO;
    }

    public ArrayList getParadasOnibusPOJO() {
        return paradasOnibusPOJO;
    }

    public void setParadasOnibusPOJO(ArrayList paradasOnibusPOJO) {
        this.paradasOnibusPOJO = paradasOnibusPOJO;
    }
/*
    public ParadaOnibusPOJO[] getParadasOnibusPOJO() {
        return paradasOnibusPOJO;
    }

    public void setParadasOnibusPOJO(ParadaOnibusPOJO[] paradasOnibusPOJO) {
        this.paradasOnibusPOJO = paradasOnibusPOJO;
    }
*/

    public RedePOJO[] getRedePOJO() {
        return redePOJO;
    }

    public void setRedePOJO(RedePOJO[] redePOJO) {
        this.redePOJO = redePOJO;
    }

    public RotaPOJO[] getRotaPOJO() {
        return rotaPOJO;
    }

    public void setRotaPOJO(RotaPOJO[] rotaPOJO) {
        this.rotaPOJO = rotaPOJO;
    }

    public VeiculoPOJO[] getVeiculoPOJO() {
        return veiculoPOJO;
    }

    public void setVeiculoPOJO(VeiculoPOJO[] veiculoPOJO) {
        this.veiculoPOJO = veiculoPOJO;
    }

    public PeriodoEtaPOJO[] getPeriodoEtaPOJO() {
        return periodoEtaPOJO;
    }

    public void setPeriodoEtaPOJO(PeriodoEtaPOJO[] periodoEtaPOJO) {
        this.periodoEtaPOJO = periodoEtaPOJO;
    }
    private Table table1 = new Table();
    private Dynamic dynamic = null;


    public Table getTable1() {
          return table1;
    }

    public void setTable1(Table t) {
        this.table1 = t;
    }
    private DropDown dropDown1 = new DropDown();

    public DropDown getDropDown1() {
        return dropDown1;
    }

    public void setDropDown1(DropDown dd) {
        this.dropDown1 = dd;
    }
    private DropDown dropDown2 = new DropDown();

    public DropDown getDropDown2() {
        return dropDown2;
    }

    public void setDropDown2(DropDown dd) {
        this.dropDown2 = dd;
    }
    private DropDown dropDown3 = new DropDown();

    public DropDown getDropDown3() {
        return dropDown3;
    }

    public void setDropDown3(DropDown dd) {
        this.dropDown3 = dd;
    }
    private DropDown dropDown4 = new DropDown();

    public DropDown getDropDown4() {
        return dropDown4;
    }

    public void setDropDown4(DropDown dd) {
        this.dropDown4 = dd;
    }
    private Button button1 = new Button();

    public Button getButton1() {
        return button1;
    }

    public void setButton1(Button b) {
        this.button1 = b;
    }
    private DefaultTableDataModel dataTable1Model1 = new DefaultTableDataModel();

    public DefaultTableDataModel getDataTable1Model1() {
        return dataTable1Model1;
    }

    public void setDataTable1Model1(DefaultTableDataModel dtdm) {
        this.dataTable1Model1 = dtdm;
    }




    // </editor-fold>
    /**
     * <p>Construct a new Page bean instance.</p>
     */
    public BuscaDados() throws BusmsException {

            this.atualizaVeiculo();
            this.atualizaRede();
            this.atualizaRota();
            this.atualizaPeriodoEta();
            this.setTable1(getTable1());
            this.getSessionBean1();
           // this.atualizaTabela();
        
        
        
       


            }

    /**
     * <p>Callback method that is called whenever a page is navigated to,
     * either directly via a URL, or indirectly via page navigation.
     * Customize this method to acquire resources that will be needed
     * for event handlers and lifecycle methods, whether or not this
     * page is performing post back processing.</p>
     *
     * <p>Note that, if the current request is a postback, the property
     * values of the components do <strong>not</strong> represent any
     * values submitted with this request.  Instead, they represent the
     * property values that were saved for this view when it was rendered.</p>
     */
    @Override
    public  void init() {
        // Perform initializations inherited from our superclass



        super.init();



        // Perform application initialization that must complete
        // *before* managed components are initialized
        // TODO - add your own initialiation code here

        // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
        // Initialize automatically managed components
        // *Note* - this logic should NOT be modified
        try {
            _init();
            
            
            this.atualizaVeiculo();
            this.atualizaRede();
            this.atualizaRota();
            this.atualizaPeriodoEta();
            this.setTable1(getTable1());
            this.getSessionBean1();

           
            
            
            
            


            

            

        } catch (Exception e) {
            log("Page1 Initialization Failure", e);
            throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
        }

    // </editor-fold>
    // Perform application initialization that must complete
    // *after* managed components are initialized
    // TODO - add your own initialization code here

    }

    /**
     * <p>Callback method that is called after the component tree has been
     * restored, but before any event processing takes place.  This method
     * will <strong>only</strong> be called on a postback request that
     * is processing a form submit.  Customize this method to allocate
     * resources that will be required in your event handlers.</p>
     */
    @Override
    public void preprocess() {

                
    }

    /**
     * <p>Callback method that is called just before rendering takes place.
     * This method will <strong>only</strong> be called for the page that
     * will actually be rendered (and not, for example, on a page that
     * handled a postback and then navigated to a different page).  Customize
     * this method to allocate resources that will be required for rendering
     * this page.</p>
     */
    @Override
    public void prerender() {

                
            }

    /**
     * <p>Callback method that is called after rendering is completed for
     * this request, if <code>init()</code> was called (regardless of whether
     * or not this was the page that was actually rendered).  Customize this
     * method to release resources acquired in the <code>init()</code>,
     * <code>preprocess()</code>, or <code>prerender()</code> methods (or
     * acquired during execution of an event handler).</p>
     */
    @Override
    public void destroy() {
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected SessionBean1 getSessionBean1() {
        return (SessionBean1) getBean("SessionBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected RequestBean1 getRequestBean1() {
        return (RequestBean1) getBean("RequestBean1");
    }

    /**
     * <p>Return a reference to the scoped data bean.</p>
     *
     * @return reference to the scoped data bean
     */
    protected ApplicationBean1 getApplicationBean1() {
        return (ApplicationBean1) getBean("ApplicationBean1");
    }

    public void buscaDados() throws BusmsException {

            this.atualizaVeiculo();
            this.atualizaRede();
            this.atualizaRota();
            this.atualizaPeriodoEta();
            this.getSessionBean1();
            this.setPage1(page1);
            this.atualizaTabela();
            
     
            
    }

    public void atualizaTabela() throws BusmsException {

        ParadaOnibus objParadaOnibus = new ParadaOnibus();


        this.setParadasOnibusPOJO(
                objParadaOnibus.buscaParadas(idRede,idRota,
                                idVeiculo));
      }

    public void atualizaVeiculo() throws BusmsException {

        Veiculo objVeiculo = new Veiculo();

        this.setVeiculoPOJO(objVeiculo.buscaVeiculo());

    }

    public void atualizaRede() throws BusmsException {

        Rede objRede = new Rede();

        this.setRedePOJO(objRede.buscaRede());


    }

    public void atualizaRota() throws BusmsException {

        Rota objRota = new Rota();

        this.setRotaPOJO(objRota.buscaRota());


    }

    public void atualizaPeriodoEta() throws BusmsException {

        PeriodoEta objPeriodoEta = new PeriodoEta();

        this.setPeriodoEtaPOJO(objPeriodoEta.buscaPeriodoEta());


    }

    public void atualizaUsuario() throws BusmsException {

        Usuario objUsuario = new Usuario();

        this.setUsuarioPOJO(objUsuario.buscaUsuario());
    }

    //========================
    //BOTAO
    //========================
    public ArrayList button1_action() throws BusmsException {



        try {

            
            this.atualizaTabela();
       }

       catch (BusmsException ex) {

        JOptionPane.showMessageDialog(null,ex,"BusMs",JOptionPane.ERROR_MESSAGE);

      }
        catch (Exception ex) {

           JOptionPane.showMessageDialog(null, ex.getMessage());
        }
        finally{
            DefaultTableDataModel.newDefaultData();
      }
        return null;
    }
  
    public void dropDownRede(ValueChangeEvent event) {

        try {

            this.idRede = event.getNewValue().toString();

        } catch (Exception exp) {

            exp.getCause();
            exp.getMessage();
        }

    }

    public void dropDownRota(ValueChangeEvent event) {

        try {

           idRota = event.getNewValue().toString();

        } catch (Exception exp) {

            exp.getCause();
            exp.getMessage();
        }

    }

 public void dropDownVeiculo(ValueChangeEvent event) {

        try {

            idVeiculo = event.getNewValue().toString();

        } catch (Exception exp) {

            exp.getCause();
            exp.getMessage();
        }

    }



    public void dropDownPeriodoEta(ValueChangeEvent event) {

        try {

            //Tem que ajeitar pois nao pega o id e sim o String
            idPeriodoEta = event.getNewValue().toString();

        } catch (Exception exp) {

            exp.getCause();
            exp.getMessage();
        }

    }

    public void dropDown1_validate(FacesContext context, UIComponent component, Object value) {
    }

    public void dropDown2_validate(FacesContext context, UIComponent component, Object value) {
    }

    public void dropDown3_validate(FacesContext context, UIComponent component, Object value) {
    }

}
Criado 16 de julho de 2009
Respostas 0
Participantes 1