9 Replies Latest reply on Jun 18, 2008 2:36 PM by sammy Jenkis

    clean fields with JSF and RichFaces

    leandro godoy Apprentice


      How to clear the fields with jsf and RichFaces, tried using javaScript but naum worked, someone knows how to do this?
      thanks,hugs.

        • 1. Re: clean fields with JSF and RichFaces
          Sergey Smirnov Master

          You are extremely short today. I am not sure I know why your fields are dirty.

          • 3. Re: clean fields with JSF and RichFaces
            leandro godoy Apprentice

            even create a new object when the fields are still dirty, not clean in any way
            ,:(

            • 4. Re: clean fields with JSF and RichFaces
              Ilya Shaikovsky Master

              as Sergey already told you - it will be better to show us your code and explain more carefull the case you've implemented.

              • 5. Re: clean fields with JSF and RichFaces
                leandro godoy Apprentice

                but I understand it, see it with my bean scope of sitting on a page have a tabeddPanel this tabeddPanel a tab displays a list of items and another tab displays a form of registration, I have two buttons one saves a register and changes to the tab list and tab in the new list have a button that sends the tab to register, but the tab record the old data are still there, and on the bean was created a new object.
                see snippets of code:

                
                <rich:tabPanel switchType="client" id="tabpaneln"
                title="Numeracao" label="Numeracao"
                selectedTab="#{produto.tabSet}" rendered="#{!produto.viewState}" immediate="true">
                <rich:tab label="Numeracao" immediate="true" id="tbnumeracao"
                ajaxSingle="true">
                <rich:datascroller align="center" for="tbprodnum" maxPages="20"
                style=" width : 600px;" />
                <rich:dataTable
                onRowMouseOver="this.style.backgroundColor='#F1F1F1'"
                onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'"
                cellpadding="0" cellspacing="0" rows="5" width="650"
                 border="4" var="iv" value="#{produto.modelpn}" id="tbprodnum"
                 style=" width : 736px;">
                <f:facet name="header">
                 <rich:columnGroup>
                <rich:column rowspan="2">
                <h:outputText value="#{msg.acoes}"></h:outputText>
                <rich:separator height="12" styleClass="tooltip"></rich:separator>
                <a4j:commandLink id="novopn" action="#{produto.novopn}"
                 immediate="true" reRender="tabpaneln">
                
                ... This Second Tab
                
                 <rich:tab label="Cadastrar" ajaxSingle="true" immediate="true" id="tbcad">
                 <rich:panelBar height="245" width="712">
                 <rich:panelBarItem label="#{msg.pedidos}">
                 <h:panelGrid columns="2" width="455">
                 <h:outputText value="#{msg.numeracao}"></h:outputText>
                 <h:panelGroup>
                 <h:selectOneMenu
                 value="#{produto.produtoNumeracao.numeracao}" required="true"
                 id="combo">
                <f:selectItems value="#{produto.numeracaoids}" />
                 <f:converter converterId="numeracaoconversor" />
                 </h:selectOneMenu>
                <a4j:commandLink style="cursor:pointer" action="#{numeracao.novo}"
                 immediate="true" ajaxSingle="true" ignoreDupResponses="true"
                 oncomplete="Richfaces.showModalPanel('loadNumeracao')" >
                <h:graphicImage value="/images/newButtons/add.png" width="20"
                 height="20" style="border:0" >
                 </h:graphicImage>
                 </a4j:commandLink>
                </h:panelGroup>
                
                 <h:outputText value="#{msg.qtdatual}"></h:outputText>
                 <h:inputText value="#{produto.produtoNumeracao.qtdatual}"
                 label="Numeração" maxlength="3" required="true"
                 id="num"onkeypress="mascara(this,soNumeros)">
                 <f:validateLongRange minimum="0" maximum="999"/>
                 </h:inputText>
                
                 <h:outputText value="#{msg.qtdmin}"></h:outputText>
                 <h:inputText value="#{produto.produtoNumeracao.qtdminima}"
                 id="qtdmin" style=" width : 198px;" onkeypress="mascara(this,soNumeros)">
                 <f:validateLongRange minimum="0" maximum="999"/>
                 </h:inputText>
                
                
                
                 <h:outputText value="#{msg.qtdmax}"></h:outputText>
                 <h:panelGroup>
                 <h:inputText value="#{produto.produtoNumeracao.qtdmaxima}"
                 onkeypress="mascara(this,soNumeros)"
                 style=" width : 198px;" required="true" id="qtdmax" onblur="return checkQtd()">
                 <f:validateLongRange minimum="0" maximum="999"/>
                 </h:inputText>
                
                 </h:panelGroup>
                 </h:panelGrid>
                 <center>
                 <a4j:commandButton
                 action="#{produto.createpn}" value="salvar" id="salvar" reRender="tbprodnum,tabpaneln" >
                 <f:setPropertyActionListener target="#{produto.id}"
                 value="#{produto.produto.produtoid}" />
                 </a4j:commandButton>
                
                


                These are the methods in the bean called by the buttons
                (<a4j:commandButton action="#{produto.createpn}" value="salvar" id="salvar")

                (<a4j:commandLink id="novopn" action="#produto.novopn}")


                
                public String novopn() {
                 produtoNumeracao = new ProdutoNumeracao();
                 setTabSet("tbcad");
                 return "";
                 }
                
                
                public String createpn() {
                 if(produtoNumeracao.getQtdmaxima()<produtoNumeracao.getQtdminima()){
                 mensagem("chekqtd");
                 return null;
                 }else{
                 IDaoProdutoNumeracao ldao = new DaoProdutoNumeracao();
                 ProdutoNumeracaoPK pnpk = new ProdutoNumeracaoPK(produto.getProdutoid()
                 ,produtoNumeracao.getNumeracao().getNumeracaoid());
                 produtoNumeracao.setProdutoNumeracaoPK(pnpk);
                 ldao.salvar(produtoNumeracao);
                 setTabSet("tbnumeracao");
                 // somaTotalPares();
                 getTodosProdutoNumeracao();
                 return "";
                 }
                
                 }
                
                


                The only problem I'm having and that the old values remain in the form of registration, even when it created a new object.
                Thank you all for your attention, hugging.

                See image
                http://www.4shared.com/file/51788845/4db9b400/aba1.html http://www.4shared.com/file/51788852/cac610e2/aba2.html

                • 6. Re: clean fields with JSF and RichFaces
                  sammy Jenkis Newbie

                  Not sure if this is related, but...

                  I have seen a problem where old values unexpectedly hang around in text fields when using a4j. While debugging, I stepped into the JSF RI and found that the value binding had the correct, new value, but the HtmlInput will display the submitted value if it has it (in this case, the old value). Not sure if this is a bug or not, but it was unexpected behavior from my point of view, because my model changed, and I rerendered a region, but I still got old values.

                  To work around this, I put my a4j button in a little a4j region and set it up as ajaxSingle. This way, the request values for the other fields on the form weren't applied to the HtmlInputs, and so they properly rendered the value of their binding again.

                  I don't fully understand that problem, but I thought I'd throw it out there.

                  • 7. Re: clean fields with JSF and RichFaces
                    leandro godoy Apprentice

                    Hello friend, thank you follow their instructions and managed to achieve a satisfactory result using a (<a4j: region),
                    thank you very much, hugging. :)

                    • 8. Re: clean fields with JSF and RichFaces
                      Sergey Smirnov Master

                       

                      "mmichalek" wrote:
                      Not sure if this is related, but...

                      I have seen a problem where old values unexpectedly hang around in text fields when using a4j.


                      First off, the behaviour is very expected, because is is a core JSF behaviour.
                      RichFaces (aka a4j) adds nothing to the scene.

                      Why JSF works like that is illustrated in the RichFaces' cookbook article:
                      http://wiki.jboss.org/wiki/RichFacesTwoInputText


                      People wonder about form cleaning from the very beginning.
                      This is a form post that was 4 (four!) years ago:
                      http://forum.java.sun.com/thread.jspa?forumID=427&threadID=528778

                      Not RichFaces, but even, nor Ajax words were officially pronounced yet.






                      • 9. Re: clean fields with JSF and RichFaces
                        sammy Jenkis Newbie

                        Thanks Sergey - that's good info.