Ajuda com TSeekButton Estou utilizando o componente TSeekButton e se clicar na "lupa" a tela funciona corretamente. A tela que estou com este problema é uma tela de contatos onde possuo uma outra tabela de tipos de contatos. O problema é que ao entrar no formulário de contato, eu ja tenho o codigo do tipo de contato cadastrado. Mas nao aparece a descricao do tipo de contato na tela (conforme imagem anexada) S...
NP
Ajuda com TSeekButton  
Fechado
Estou utilizando o componente TSeekButton e se clicar na "lupa" a tela funciona corretamente.
A tela que estou com este problema é uma tela de contatos onde possuo uma outra tabela de tipos de contatos.

O problema é que ao entrar no formulário de contato, eu ja tenho o codigo do tipo de contato cadastrado. Mas nao aparece a descricao do tipo de contato na tela (conforme imagem anexada)

Se eu clico no campo "Tipo Contato" e saio deste campo atraves da tecla TAB (exit), ai aparece a descricao do tipo de contato certinho.

Eu peguei as classes CustomerDataGridView , CustomerFormView e CitySeek e adaptei conforme as minhas tabelas.

Alguém tem alguma dica para me ajudar ? Pois ja olhei o exemplo da classe "CustomerFormView" (tutor) e tambem a classe "CitySeek" e não consegui achar nenhuma diferença.

A sequencia de execução é a seguinte:

1-) Entro na primeira tela do Grid (ContatoDataGridView)
2-) Seleciono um registro e clico no botao "editar" , é chamada a classe "ContatoFormView"

É nesta classe "ContatoFormView" que não aparece a descrição do Tipo de Contato.

abaixo segue o codigo php da classe ContatoFormView:

<?php/** * ContatoFormView */class ContatoFormView extends TPage{    private $form; // form        /**     * Class constructor     * Creates the page and the registration form     */    function __construct()    {        parent::__construct();        // creates the form        $this->form = new TForm('form_contato');                // creates a table        $table_data      = new TTable;        $table_telefones = new TTable;        $table_emails    = new TTable;                $notebook = new TNotebook(500, 250);        // add the notebook inside the form        $this->form->add($notebook);                $notebook->appendPage('Registrar Dados',     $table_data);        $notebook->appendPage('Contato (telefones)', $table_telefones);        $notebook->appendPage('Contato (e-mail)',    $table_emails);                // create the form fields        $contato_id        = new TEntry('contato_id');        $tipo_contato_id   = new TSeekButton('tipo_contato_id');        $tipocontato_nome  = new TEntry('tipocontato_nome');        $nome_contato      = new TEntry('nome_contato');        $endereco          = new TEntry('endereco');        $bairro            = new TEntry('bairro');        $cep               = new TEntry('cep');        $cidade            = new TEntry('cidade');        $uf                = new TEntry('uf');        $ponto_referencia  = new TEntry('ponto_referencia');        $observacoes       = new TEntry('observacoes');        $responsavel_id    = new TEntry('responsavel_id');        $dt_inclusao       = new TDate('dt_inclusao');        $status            = new TCombo('status');                $telefone_comercial   = new TEntry('telefone_comercial');        $telefone_residencial = new TEntry('telefone_residencial');        $telefone_contato     = new TEntry('telefone_contato');        $telefone_celular     = new TEntry('telefone_celular');        $telefone_consultorio = new TEntry('telefone_consultorio');        $email_comercial      = new TEntry('email_comercial');        $email_contato        = new TEntry('email_contato');        $email_particular     = new TEntry('email_particular');                $responsavel_id->setValue(TSession::getValue('login')); // Buscar o login do usuario logado - 21/06/2016        $responsavel_id->setEditable(false);         /* ---------------------------------------------------------------------------------*/        $dt_inclusao->setValue( date('Y/m/d', mktime(0, 0, 0, date("m")  , date("d"), date("Y")) ));        $contato_id->setEditable(false);        $cbo_stat = array();        $cbo_stat['AT'] = 'Ativo';        $cbo_stat['IN'] = 'Inativo';        $cbo_stat['CA'] = 'Cancelado';        $cbo_stat['EX'] = 'Excluido';        $status->addItems($cbo_stat);        $status->setValue('AT');        /* ---------------------------------------------------------------------------------*/                // add field validators        $nome_contato->addValidation('Nome Contato', new TRequiredValidator);        $tipo_contato_id->addValidation('Tipo do Contato', new TRequiredValidator);                //--------------------------------------------------------------------------//        //----------[ Aqui é onde se busca o Tipo de Contato ]----------------------//        //--------------------------------------------------------------------------//        $obj = new TipoContatoSeek;        $tipo_contato_id->setAction(new TAction(array($obj, 'onReload')));        //--------------------------------------------------------------------------//        // define the action for city_id1        //$obj    = new TipoContatoSeek;        //$action = new TAction(array($obj, 'onReload'));        //$tipo_contato_id->setAction($action);        //--------------------------------------------------------------------------//        // Define o Comprimento e largura        $contato_id->setSize(40);        $tipo_contato_id->setSize(50);        $tipocontato_nome->setSize(327);         $nome_contato->setSize(400);        $endereco->setSize(400);        $bairro->setSize(300);        $cep->setSize(150);        $cidade->setSize(400);        $uf->setSize(40);        $ponto_referencia->setSize(400);        $observacoes->setSize(400);                $telefone_comercial->setSize(160);        $telefone_residencial->setSize(160);        $telefone_contato->setSize(160);        $telefone_celular->setSize(160);        $telefone_consultorio->setSize(160);        $email_comercial->setSize(300);        $email_contato->setSize(300);        $email_particular->setSize(300);                // add a row for the field code        $table_data->addRowSet(new TLabel('ID:'), $contato_id);        $table_data->addRowSet(new TLabel('Tipo Contato:'), array($tipo_contato_id, new TLabel('Nome:'),$tipocontato_nome));        $table_data->addRowSet(new TLabel('Nome Contato:'), $nome_contato);        $table_data->addRowSet(new TLabel('Endereco:'), array($endereco, new TLabel('Bairro:'), $bairro));        $table_data->addRowSet(new TLabel('Cidade:'),   array($cidade, new TLabel('Cep:'), $cep, new TLabel('UF:'), $uf));        $table_data->addRowSet(new TLabel('Ponto Referencia:'), $ponto_referencia);        $table_data->addRowSet(new TLabel('Observacoes:'), $observacoes);        $table_data->addRowSet(new TLabel('Status:'), $status);        $contato_id->setEditable(FALSE);        $tipocontato_nome->setEditable(FALSE);                $row  = $table_telefones->addRow();        $cell = $row->addCell(new TLabel('<b>Numeros de Telefones</b>'));        $cell->valign = 'top';                // add two fields inside the multifield in the second sheet        $table_telefones->addRowSet(new TLabel('Comercial:'), $telefone_comercial);        $table_telefones->addRowSet(new TLabel('Residencial:'), $telefone_residencial);        $table_telefones->addRowSet(new TLabel('Celular:'), $telefone_celular);        $table_telefones->addRowSet(new TLabel('Consultorio:'), $telefone_consultorio);        $table_telefones->addRowSet(new TLabel('Contato:'), $telefone_contato);        $row  = $table_emails->addRow();        $cell = $row->addCell(new TLabel('<b>E-mails para Contato</b>'));        $cell->valign = 'top';                // add two fields inside the multifield in the second sheet        $table_emails->addRowSet(new TLabel('Comercial:'),  $email_comercial);        $table_emails->addRowSet(new TLabel('Particular:'), $email_particular);        $table_emails->addRowSet(new TLabel('Contato:'),    $email_contato);                // create an action button        $button1=new TButton('button1');        $button1->setAction(new TAction(array($this, 'onSave')), 'Salvar');        $button1->setImage('ico_save.png');                // create an action button (go to list)        $button2=new TButton('button2');        $button2->setAction(new TAction(array('ContatoDataGridView', 'onReload')), 'Retorna');        $button2->setImage('ico_datagrid.gif');                $this->form->setFields(array($contato_id, $tipo_contato_id, $tipocontato_nome,                                      $nome_contato, $endereco, $bairro, $cep, $cidade,                                      $uf, $ponto_referencia, $telefone_comercial, $telefone_residencial,                                      $telefone_contato, $telefone_celular, $telefone_consultorio,                                      $email_comercial, $email_contato, $email_particular,                                      $observacoes, $dt_inclusao, $responsavel_id, $status, $button1, $button2));        $subtable = new TTable;        $row = $subtable->addRow();        $row->addCell($button1);        $row->addCell($button2);                // wrap the page content        $vbox = new TVBox;        $vbox->add(new TXMLBreadCrumb('menu.xml', 'ContatoDataGridView'));        $vbox->add($this->form);        $vbox->add($subtable);                // add the form inside the page        parent::add($vbox);    }        /**     * method onSave     * Executed whenever the user clicks at the save button     */    function onSave()    {        try        {            // open a transaction with database 'sgp'            TTransaction::open('sgp');            $this->form->validate();            // read the form data and instantiates an Active Record            $Contato = $this->form->getData('Contato');                        if ($Contato->contacts_list)            {                foreach ($Contato->contacts_list as $contact)                {                    // add the contact to the Contato                    $Contato->addContact($contact);                }            }                        if ($Contato->skill_list)            {                foreach ($Contato->skill_list as $skill_id)                {                    // add the skill to the Contato                    $Contato->addSkill(new Skill($skill_id));                }            }            // stores the object in the database            $Contato->store();            $this->form->setData($Contato);                        // shows the success message            new TMessage('info', 'Record saved');                        TTransaction::close(); // close the transaction        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b>: ' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }        /**     * method onEdit     * Edit a record data     */    function onEdit($param)    {        try        {            if (isset($param['key']))            {                // open a transaction with database 'sgp'                TTransaction::open('sgp');                                // load the Active Record according to its ID                $Contato = new Contato($param['key']);                                // load the contacts (composition)                //////$Contato->contacts_list = $Contato->Contatos();                                // load the skills (aggregation)                $skills = $Contato->getContatos();                $skill_list = array();                if ($skills)                {                    foreach ($skills as $skill)                    {                        $skill_list[] = $skill->contato_id;                    }                }                $Contato->skill_list = $skill_list;                                // fill the form with the active record data                $this->form->setData($Contato);                                // close the transaction                TTransaction::close();            }            else            {                $this->form->clear();            }                    }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', '<b>Error</b>' . $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }}?>


Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


LA

Ola Nilton
mas não encontrei nenhuma ligação no seu codigo com a tabela tipos_contatos.

Tenta assim:
<?php$tipo_contato_id = new 
">TDBSeekButton('tipo_contato_id', 'conexao', 'form_contato', 'NomeDoModelDaTabelaTipos', 'descricao_tipo', 'id_tipo', 'tipocontato_nome');?>
NP

Luis Alberto bom dia, obrigado pelo retorno.

Na Classe ContatoFormView estou fazendo esta chamada e abaixo segue a classe TipoContatoSeek (tenho duvidas se é somente isso, OK ?)
//--------------------------------------------------------------------------//
//----------[ Aqui é onde se busca o Tipo de Contato ]----------------------//
//--------------------------------------------------------------------------//
$obj = new TipoContatoSeek;
$tipo_contato_id->setAction(new TAction(array($obj, 'onReload')));
//--------------------------------------------------------------------------//

TipoContatoSeek:
<?php/** * Tipo Contato Search Form * @author     Nilton Prospero * @copyright  Copyright (c) 2016 APMPS-DR. (http://www.apmps.org.br) */class TipoContatoSeek extends TWindow{    private $form;      // form    private $datagrid;  // datagrid    private $pageNavigation;    private $loaded;        /**     * Class constructor     * Creates the page, the search form and the listing     */    public function __construct()    {        parent::__construct();        parent::setSize(700, 500);        parent::setTitle('Busca Informacao');        new TSession;                // creates the form        $this->form = new TQuickForm('form_search_tpcontato');        $this->form->class = 'tform';        $this->form->setFormTitle('Tipos de Contato');                // create the form fields        $name   = new TEntry('name');        $name->setValue(TSession::getValue('tipocontato_nome'));                // add the form fields        $this->form->addQuickField('Name', $name,  300);        // define the form action        $this->form->addQuickAction('Busca', new TAction(array($this, 'onSearch')), 'ico_find.png');                // creates a DataGrid        $this->datagrid = new TQuickGrid;        $this->datagrid->style = 'width: 100%';        $this->datagrid->setHeight(130);        $this->datagrid->enablePopover('Tipo Contato', ' {descricao}');                // creates the datagrid columns        $this->datagrid->addQuickColumn('Id', 'tipo_contato_id', 'right', 40);        $this->datagrid->addQuickColumn('Tipo Contato', 'descricao', 'left', 340);        // creates two datagrid actions        $this->datagrid->addQuickAction('Seleciona', new TDataGridAction(array($this, 'onSelect')), 'tipo_contato_id', 'ico_apply.png');                // create the datagrid model        $this->datagrid->createModel();                // creates the page navigation        $this->pageNavigation = new TPageNavigation;        $this->pageNavigation->setAction(new TAction(array($this, 'onReload')));        $this->pageNavigation->setWidth($this->datagrid->getWidth());                // creates a container        $container = new TVBox;        $container->style = 'width: 100%';        $container->add($this->form);        $container->add($this->datagrid);        $container->add($this->pageNavigation);                // add the container inside the page        parent::add($container);    }        /**     * method onSearch()     * Register the filter in the session when the user performs a search     */    function onSearch()    {        // get the search form data        $data = $this->form->getData();                // check if the user has filled the form        if (isset($data->name))        {            // creates a filter using what the user has typed            $filter = new TFilter('descricao', 'like', "%{$data->name}%");                        // stores the filter in the session            TSession::setValue('tpcontato_filter', $filter);            TSession::setValue('tipocontato_nome', $data->name);                        // fill the form with data again            $this->form->setData($data);        }                // redefine the parameters for reload method        $param = array();        $param['offset']     = 0;        $param['first_page'] = 1;                $this->onReload($param);    }        /**     * Load the datagrid with the database objects     */    function onReload($param = NULL)    {        try        {            // open a transaction with database 'samples'            TTransaction::open('sgp');                        // creates a repository for Tipos de Contato            $repository = new TRepository('TipoContato');            $limit = 10;            // creates a criteria            $criteria = new TCriteria;                        // default order            if (!isset($param['order']))            {                $param['order'] = 'tipo_contato_id';                $param['direction'] = 'asc';            }                        $criteria->setProperties($param); // order, offset            $criteria->setProperty('limit', $limit);                        if (TSession::getValue('tpcontato_filter'))            {                // add the filter stored in the session to the criteria                $criteria->add(TSession::getValue('tpcontato_filter'));            }                        // load the objects according to the criteria            $tpcontato = $repository->load($criteria);            $this->datagrid->clear();            if ($tpcontato)            {                foreach ($tpcontato as $tpcontatos)                {                    // add the object inside the datagrid                    $this->datagrid->addItem($tpcontatos);                }            }                        // reset the criteria for record count            $criteria->resetProperties();            $count = $repository->count($criteria);                        $this->pageNavigation->setCount($count); // count of records            $this->pageNavigation->setProperties($param); // order, page            $this->pageNavigation->setLimit($limit); // limit                        // close the transaction            TTransaction::close();            $this->loaded = true;        }        catch (Exception $e) // in case of exception        {            // shows the exception error message            new TMessage('error', $e->getMessage());            // undo all pending operations            TTransaction::rollback();        }    }        /**     * Executed when the user chooses the record     */    public function onSelect($param)    {        try        {            $key = $param['key'];                        TTransaction::open('sgp');                        // load the active record            $tipocontato = new TipoContato($key);                          // closes the transaction            TTransaction::close();                        $object = new StdClass;            $object->tipo_contato_id  = $tipocontato->tipo_contato_id;            $object->tipocontato_nome = $tipocontato->descricao;            TForm::sendData('form_contato', $object);            parent::closeWindow(); // close the window        }        catch (Exception $e) // em caso de exceção        {            // clear fields            $object = new StdClass;            $object->tipo_contato_id  = '';            $object->tipocontato_nome = '';            TForm::sendData('form_contato', $object);                        // undo pending operations            TTransaction::rollback();        }    }        /**     * Shows the page     */    function show()    {        // if the datagrid was not loaded yet        if (!$this->loaded)        {            $this->onReload();        }        parent::show();    }}
NR

Nilton, crie a seguinte função no model Contato
<?phpfunction get_tipocontato_nome(){     return $this->get_tipo_contato()->descricao;}?>

Só confirme que a função get_tipo_contato já exista no model Contato.
NP

Nataniel boa noite.

Muito obrigado pela resposta, funcionou direitinho.

Parabéns pelo conhecimento e obrigado pela ajuda

** E obrigado ao Luis Alberto também pela ajuda.

Grande abraço,
Nilton.
RS

desculpa Nataniel e Nilton poderiam me ajudar, estou com este problema com TSeeekButton, creio que é o mesmo B.O , no onEdit não traz o nome_cli fica em branco

<?php      $nome_cli  = new TEntry('nome_cli');        $nome_cli->setEditable(false);                $cliente_id = new TSeekButton('cliente_id');        $cliente_id->setAction( new TAction(['ClienteSeek', 'onReload']) );        $cliente_id->setAuxiliar($nome_cli);?>