2 Replies Latest reply on Nov 10, 2009 3:03 PM by fmontezuma

    Weird behaviour when submit using @Out property

    fmontezuma

      Hi!


      I´m having problems when I try to set a value to my bean.


      I want to set the current classification value to it, but somehow it's having a weird behavior.


      Here is the code:


      @Name("classificacaoAction")
      @Scope(ScopeType.CONVERSATION)
      public class ClassificacaoAction
      {
           @In(create = true)
           private List<SofClassificacao> listaClassificacoes;
           
           @Out(required = false)
           private SofClassificacaoRomaneio classificacaoAtual;
           
           @In
           private GerenciarRomaneioAction sofGerenciarRomaneioAction;
           
           @Out
           private SofRomaneio romaneio;
                
           @Factory(value = "romaneio", autoCreate = true)
           public void carregarRomaneio()
           {          
                romaneio = sofGerenciarRomaneioAction.getRomaneio();
                
                // inicializa classificacoes
                if (romaneio.getSofClassificacaoRomaneios().isEmpty())
                {
                     romaneio.setSofClassificacaoRomaneios(new LinkedHashSet<SofClassificacaoRomaneio>());
                     Set<SofClassificacaoRomaneio> lista = romaneio.getSofClassificacaoRomaneios();
                     
                     for (SofClassificacao classificacao : listaClassificacoes)
                     {
                          SofClassificacaoRomaneio classificacaoRomaneio = new SofClassificacaoRomaneio();
                          classificacaoRomaneio.setSofRomaneio(romaneio);
                          classificacaoRomaneio.setSofClassificacao(classificacao);
                          classificacaoRomaneio.setPcDesconto(BigDecimal.ONE);
                          lista.add(classificacaoRomaneio);
                     }
                }
                classificacaoAtual = romaneio.getSofClassificacaoRomaneios().iterator().next();
           }     
                
           public void proximaClassificacao()
           {
                if (classificacaoAtual != null)
                {
                     Integer classificacaoAtualId = classificacaoAtual.getId().getCdClassificacao();
                     
                     Iterator<SofClassificacaoRomaneio> i = romaneio.getSofClassificacaoRomaneios().iterator();
                     SofClassificacaoRomaneio cr = i.next(); // 1o valor - nunca será satisfatório
                     
                     while (i.hasNext() && cr.getId().getCdClassificacao() <= classificacaoAtualId) 
                     { 
                          cr = i.next();
                     }
                     
                     if (cr.getId().getCdClassificacao() > classificacaoAtualId)
                     {
                          classificacaoAtual = cr;
                     }
                     else
                     {
                          classificacaoAtual = null;
                     }
                }
           }          
      }



      And the page (it is included in another page, there is a form around it):


      <rich:tab label="Classificação" id="gr-aba-classificacao"
          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:s="http://jboss.com/products/seam/taglib"
          xmlns:a="http://richfaces.org/a4j"
          xmlns:rich="http://richfaces.org/rich">
           
           <s:div id="classif-romaneio" rendered="#{editarRomaneio}">
           
                <s:decorate id="classificacaoAtualField" template="layout/custom-edit.xhtml" rendered="#{classificacaoAtual != null}">
                     <ui:define name="label">#{classificacaoAtual.sofClassificacao.dsClassificacao}</ui:define>
                     <h:inputText value="#{classificacaoAtual.psDesconto}" />               
                </s:decorate>
                
                <a:commandButton action="#{classificacaoAction.proximaClassificacao}" value="Salvar" rendered="#{classificacaoAtual != null}">
                     <a:support event="oncomplete" reRender="classif-romaneio, tblClassificacoes" />
                </a:commandButton>
                
           </s:div>
                
           <rich:dataTable id="tblClassificacoes" 
                value="#{romaneio.sofClassificacaoRomaneios.toArray()}" var="_classif">
                <rich:column>
                     <f:facet name="header">Descricao</f:facet>
                     <h:outputText value="#{_classif.sofClassificacao.dsClassificacao}" />
                </rich:column>
                <rich:column>
                     <f:facet name="header">PS-Desconto</f:facet>
                     <h:outputText value="#{_classif.psDesconto}" />
                </rich:column>
                <rich:column>
                     <f:facet name="header">PC-Desconto</f:facet>
                     <h:outputText value="#{_classif.pcDesconto}" />
                </rich:column>
                
                <a:support event="onRowClick" action="#{classificacaoAction.setClassificacaoAtual(_classif)}" 
                     reRender="classif-romaneio"  rendered="#{editarRomaneio}"/>
                
           </rich:dataTable>
      </rich:tab>



      When I click the button it's calling the proximaClassificacao method but the classificacaoAtual property still have the old value (looking at debug). After the reRender I can see that the old classificacaoAtual and the new classificacaoAtual, both have the value that I typed in the input text.


      Any clue of what´s happening?


      Thanks in advance.




        • 1. Re: Weird behaviour when submit using @Out property
          asookazian

          Your Seam component is CONVERSATION scoped, but how are you starting the conversation (e.g., @Begin)?

          • 2. Re: Weird behaviour when submit using @Out property
            fmontezuma

            Your Seam component is CONVERSATION scoped, but how are you starting the conversation (e.g., @Begin)?

            Fine grained XML. But that's not the point.


            I made some modifications and now it's updating it right, but another situation appeared.


            The @Out classificacaoAtual property receive null value at some point as expected (proximaClassificacao() method).


            But when it reaches that situation JSF is not reRendering classif-romaneio div right (it should disappear).


            Some help here?