2 Replies Latest reply on Oct 19, 2012 2:04 AM by mcmurdosound

    How to change/redirect togglePanelItem thru server side

    felipeleite

      Hi, I have a rich:popupPanel with 2 rich:togglePanelItem so far.

      I'd like to validate each step on server side and depends of the result go to next step or stay on the current one.

      I've tried many ways to do that but always I go to second step no matter whats happen.

       

      Thnaks in advance

       

      My code is:

      main.xhtml

       

      <rich:popupPanel header="Editar Consulta" id="editPane" domElementAttachment="parent" autosized="true">
                  <rich:togglePanel id="wizardPanel" switchType="ajax" onitemchange="return validarPasso();" itemChangeListener="#{consultaManageBean.criarConsulta}">
                      <rich:togglePanelItem id="passo1">
                          <ui:include src="/consulta/criarPasso1.xhtml" />
                      </rich:togglePanelItem>
                      <rich:togglePanelItem id="passo2">
                          <ui:include src="/consulta/criarPasso2.xhtml" />
                      </rich:togglePanelItem>
                  </rich:togglePanel>
           </rich:popupPanel>
      

       

      criarPasso1.xhtml

       

      <div style="position:relative;height:140px">
          <h:inputHidden id="passoCorrente" value="#{consultaManageBean.passoCorrente}"/>
          <h:panelGrid id="editGrid" columns="2">
              <h:outputText value="Assunto:"/>
              <rich:select id="idAssunto" required="true" value="#{consultaManageBean.editedItem.assunto.idAssunto}" requiredMessage="Campo [Assunto] Obrigatorio" >
                  <f:selectItems value="#{assuntoManageBean.lstAssunto}" var="assunto" itemValue="#{assunto.idAssunto}" itemLabel="#{assunto.nome}" />
              </rich:select>
              <h:outputText value="Sistema:" />
              <rich:select id="idSistema" value="#{consultaManageBean.editedItem.sistema.idSistema}" required="true" requiredMessage="Campo [Sistema] Obrigatorio">
                  <f:selectItems value="#{sistemaManageBean.lstSistema}" var="sistema" itemValue="#{sistema.idSistema}" itemLabel="#{sistema.nome}" />
              </rich:select>
              <h:outputText value="Nome:" />
              <h:inputText value="#{consultaManageBean.editedItem.nome}" required="true" requiredMessage="Campo [Nome] Obrigatorio" id="nome" size="40" maxlength="70" />
              <h:outputText value="Descricao:" />
                 <h:inputTextarea value="#{consultaManageBean.editedItem.descricao}" id="descricao" cols="37" rows="3" required="true" requiredMessage="Campo [Descricao] Obrigatorio" />
                 <h:outputText value="Consulta SQL:" />
              <h:inputTextarea value="#{consultaManageBean.editedItem.consultaSql}" id="consultaSql" cols="100" rows="6" required="true" requiredMessage="Campo [Consulta SQL] Obrigatorio" />
              <h:outputText value="Tabelas Envolvidas:" />
              <h:inputTextarea value="#{consultaManageBean.editedItem.tabelasEnvolvidas}" id="tabelasEnvolvidas" cols="100" rows="6" required="true" requiredMessage="Campo [Tabelas Envolvidas] Obrigatorio" />
              <h:panelGroup />
              Obs: Separe o nome das tabelas envolvidas por ponto e virgula.
          </h:panelGrid>
          <a4j:commandButton style="float:right" value="Teste" oncomplete="#{rich:component('wizardPanel')}.switchToItem('passo2'); return false;"/>
          <div class="navPanel" style="width: 100%;">
              <a4j:commandButton style="float:right" value="Proximo &gt;&gt;">
                  <rich:toggleControl targetItem="@next" event="click" />
              </a4j:commandButton>
          </div>
          </div>
      

       

      ConsultaManageBean.java

       

      ....
      public String criarConsulta(ItemChangeEvent e) {
              String outcome = "";
              if (passoCorrente == 1) {
                 // do something for the first step. If is OK go to step two
                outcome = "criarPasso2";
      
                // else stay on the first step to fix some problem.
                outcome = "criarPasso1";
              } 
              return outcome; // outcome
          }
      ....
      
        • 1. Re: How to change/redirect togglePanelItem thru server side
          felipeleite

          Ok... I figured out a workaround...

           

          <rich:togglePanel id="wizardPanel" cycledSwitching="true" switchType="ajax">

                                         <h:message for="wizardPanel" />

                                  <rich:togglePanelItem id="steps">

                                                            <ui:include src="#{consultaManageBean.paginaAtual}" />

                                     </rich:togglePanelItem>

                           </rich:togglePanel>

                           <rich:toggleControl event="click" />

           

          And the consultaManageBean.paginaAtual contains the URL to XHTML which I want.

          The "Next" button is inside the consultaManageBean.paginaAtual page.

          Actually the togglePanel with one item is a trick, I can have any steps that I want just changing the URL at consultaManageBean.paginaAtual.

          • 2. Re: How to change/redirect togglePanelItem thru server side
            mcmurdosound

            for sole "academic" reasons  you could try and debug the:

             

            public String criarConsulta(ItemChangeEvent e) {

             

             

             

            in the event should be the UIComponent for the togglePanel. You have to cast this thing to the correct type and then you may be able to set the current item directly.

             

            If the rerendering does not work, you'll have to initiate that from here, too.