10 Replies Latest reply on Jan 9, 2009 11:56 AM by André Dantas Rocha

    Enabling tabs programatically

    André Dantas Rocha Newbie

      Hello,

      How can I enable a tab automatically? I'm trying the code below, but nothing happens.

      Could anybody help me?

      Thanks in advance,

      Andre

      <rich:tabPanel id="tabClientes" binding="#{clienteBean.tabPanel}">
      ...
      <h:form>
       <a4j:jsFunction name="onSelectionChange" action="#{clienteBean. enableTab}"/>
      </h:form>
      


      private void enableTab() {
       Iterator tabs = tabPanel.getRenderedTabs();
       while (tabs.hasNext()) {
       HtmlTab tab = (HtmlTab) tabs.next();
       if ("MyTab".equals(tab.getId())) {
       tab.setDisabled(false);
       FacesContext.getCurrentInstance().renderResponse();
       break;
       }
       }
      }
      




        • 1. Re: Enabling tabs programatically
          John Ament Master

          you need to specify a reRender in your a4j tag.

          • 2. Re: Enabling tabs programatically
            Gerrit Brehmer Newbie

            If you know the tab before rendering page you can use a client js call instead of a ajax call:

            onSelectionChange="RichFaces.switchTab('<tabPanel_id>','<tab_id>','<tab_name>');"


            • 3. Re: Enabling tabs programatically
              Nick Belaevski Master

              Hello,

              Try to add

              <a4j:jsFunction name="onSelectionChange" action="#{clienteBean. enableTab}" reRender="tabClientes" />


              • 4. Re: Enabling tabs programatically
                André Dantas Rocha Newbie

                Hello,

                Thank you for responses, but unfortunately none of these strategies work. Actually I only want to enable the tab, not switching to it.

                If I use the attribute 'reRender' the screen never stop rendering. There is a spin in my <rich:extendedDataTable> but it never display any data or returns.

                I'm using RF 3.3.0 RC1.

                Any idea?

                Thanks again,

                Andre

                • 5. Re: Enabling tabs programatically
                  André Dantas Rocha Newbie

                  Maybe there is a way to rerender only tabpanel without rerender child components... Is that possible?

                  • 6. Re: Enabling tabs programatically
                    Ilya Shaikovsky Master

                    1) Unfortunatelly you could reRender only tabPanel (with the content of the active tab in ajax or server mode) but not the tab header itself.

                    2) So now we should solve the "never stops rerendering" problem. Maybe you could share simple samlpe?

                    3) some errors at client side or at a4j:log?

                    • 10. Re: Enabling tabs programatically
                      André Dantas Rocha Newbie

                      Hi ilya_shaikovsky,

                      Below is the code of tab that never stops rendering. The most importante method is selecionarCliente().

                      There is no error...

                      Thanks again,

                      Andre


                      <?xml version="1.0" encoding="ISO-8859-1"?>
                      
                      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                      
                      <html xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:a4j="http://richfaces.org/a4j"
                       xmlns:rich="http://richfaces.org/rich">
                      
                       <ui:composition>
                      
                       <h:form id="listaClientesFormCliente">
                      
                       <rich:spacer height="5px" />
                      
                       <rich:extendedDataTable id="clientes"
                       value="#{clienteBean.allClientes}"
                       var="row"
                       width="810px" height="400px"
                       sortMode="single"
                       selectionMode="single"
                       binding="#{clienteBean.table}"
                       selection="${clienteBean.selection}"
                       onselectionchange="onSelectionChange()"
                       rows="#{clienteBean.tamanhoPagina}">
                      
                       <rich:column sortable="true"
                       sortBy="#{row.nome}"
                       filterBy="#{row.nome}"
                       width="200px"
                       filterEvent="onkeyup">
                      
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteNome}"/>
                       </f:facet>
                      
                       <h:outputText value="#{row.nome}" width="150px"/>
                       </rich:column>
                      
                       <rich:column sortable="false" width="25px">
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteUf}"/>
                       </f:facet>
                       <h:outputText value="#{row.uf}"/>
                       </rich:column>
                      
                       <rich:column sortable="false" width="110px">
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteMunicipio}"/>
                       </f:facet>
                       <h:outputText value="#{row.municipio}"/>
                       </rich:column>
                      
                       <rich:column sortable="false" width="160px">
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteEmail}"/>
                       </f:facet>
                       <h:outputText value="#{row.email}"/>
                       </rich:column>
                      
                       <rich:column sortable="false">
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteTelefone}"/>
                       </f:facet>
                       <h:outputText value="#{row.telefone}"/>
                       </rich:column>
                      
                       <rich:column sortable="false" width="160px">
                       <f:facet name="header">
                       <h:outputText value="#{rebanhoBundle.clienteObservacao}"/>
                       </f:facet>
                       <h:outputText value="#{row.observacao}"/>
                       </rich:column>
                      
                       </rich:extendedDataTable>
                      
                       <rich:spacer height="9px"/>
                      
                       <rich:datascroller align="center" for="clientes" maxPages="16"
                       page="#{clienteBean.paginaAtual}" id="scroller" />
                      
                       <a4j:jsFunction name="onSelectionChange"
                       action="#{clienteBean.selecionarCliente}" reRender="tabClientes"/>
                       </h:form>
                      
                       </ui:composition>
                      </html>
                      


                      package org.codecompany.rebanho.bean;
                      
                      import java.io.Serializable;
                      import java.util.Iterator;
                      import java.util.List;
                      
                      import javax.faces.component.UIComponent;
                      import javax.faces.component.UIPanel;
                      
                      import org.apache.log4j.Logger;
                      import org.codecompany.rebanho.model.Cliente;
                      import org.codecompany.rebanho.service.ClienteService;
                      import org.richfaces.component.UIExtendedDataTable;
                      import org.richfaces.component.UITabPanel;
                      import org.richfaces.model.selection.SimpleSelection;
                      import static org.codecompany.rebanho.util.Constants.*;
                      
                      public class ClienteBean implements Serializable {
                      
                       private static final long serialVersionUID = 1L;
                       private static final Logger logger = Logger.getLogger(ClienteBean.class);
                      
                       private UIExtendedDataTable table;
                       private SimpleSelection selection = new SimpleSelection();
                      
                       // acesso aos servicos
                       private ClienteService service;
                      
                       // cliente atual
                       private Cliente cliente;
                      
                       // utilizado para paginacao
                       private int paginaAtual = PAGINA_ATUAL;
                       private int tamanhoPagina = TAMANHO_PAGINA;
                      
                       // tabs
                       private UITabPanel tabPanel;
                       private UIPanel formPanelEdicao;
                       private UIPanel formPanelInclusao;
                      
                       public SimpleSelection getSelection() {
                       return selection;
                       }
                      
                       public void setSelection(SimpleSelection selection) {
                       this.selection = selection;
                       }
                      
                       public UIExtendedDataTable getTable() {
                       return table;
                       }
                      
                       public void setTable(UIExtendedDataTable table) {
                       this.table = table;
                       }
                      
                       public String selecionarCliente() {
                      
                       String nome = "";
                      
                       if (selection == null || table == null) {
                       throw new RuntimeException("Nao foi possivel seleciona o cliente. " +
                       "'selection' ou 'table' nao disponiveis");
                       }
                      
                       Iterator<Object> iterator = getSelection().getKeys();
                      
                       while (iterator.hasNext()) {
                       Object key = iterator.next();
                       table.setRowKey(key);
                      
                       if (table.isRowAvailable()) {
                       System.out.println("***> " + key);
                       cliente = (Cliente) table.getRowData();
                       nome = cliente.getNome();
                       break;
                       }
                       }
                      
                       logger.debug("Cliente selecionado: '" + nome + "'");
                      
                       return nome;
                      
                       }
                      
                       public UIPanel getFormPanelEdicao() {
                       return formPanelEdicao;
                       }
                      
                       public void setFormPanelEdicao(UIPanel formPanelEdicao) {
                       this.formPanelEdicao = formPanelEdicao;
                       }
                      
                       public UIPanel getFormPanelInclusao() {
                       return formPanelInclusao;
                       }
                      
                       public void setFormPanelInclusao(UIPanel formPanelInclusao) {
                       this.formPanelInclusao = formPanelInclusao;
                       }
                      
                       public void setService(ClienteService service) {
                       this.service = service;
                       }
                      
                       public ClienteService getService() {
                       return service;
                       }
                      
                       public int getPaginaAtual() {
                       return paginaAtual;
                       }
                      
                       public void setPaginaAtual(int paginaAtual) {
                       this.paginaAtual = paginaAtual;
                       }
                      
                       public int getTamanhoPagina() {
                       return tamanhoPagina;
                       }
                      
                       public void setTamanhoPagina(int tamanhoPagina) {
                       this.tamanhoPagina = tamanhoPagina;
                       }
                      
                       public UITabPanel getTabPanel() {
                       return tabPanel;
                       }
                      
                       public void setTabPanel(UITabPanel tabPanel) {
                       this.tabPanel = tabPanel;
                       }
                      
                       public UIPanel getFormPanel() {
                       return formPanelEdicao;
                       }
                      
                       public void setFormPanel(UIPanel formPanel) {
                       this.formPanelEdicao = formPanel;
                       }
                      
                       public Cliente getCliente() {
                       return cliente;
                       }
                      
                       public void setCliente(Cliente cliente) {
                       this.cliente = cliente;
                       }
                      
                       public List<Cliente> getAllClientes() {
                       return service.findAll();
                       }
                      
                       public void salvarCliente() {
                       cliente.setFlag(FLAG_ATIVO);
                       service.save(this.cliente);
                       }
                      
                       public void editarCliente() {
                       cliente.setFlag(FLAG_ATIVO);
                       service.update(this.cliente);
                       }
                      
                       public void excluirCliente() {
                       cliente.setFlag(FLAG_INATIVO);
                       service.delete(this.cliente);
                       }
                      
                       public void novoCliente() {
                       cliente = new Cliente();
                       }
                      
                       public void exibirListagemClientes() {
                       limparPanel();
                       tabPanel.setSelectedTab("tabListagem");
                       }
                      
                       private void limparPanel() {
                       this.cliente = new Cliente();
                       this.cleanSubmittedValues(this.formPanelEdicao);
                       this.cleanSubmittedValues(this.formPanelInclusao);
                       }
                      
                       private void cleanSubmittedValues(UIComponent component) {
                       component.getChildren().clear();
                       }
                      }