7 Replies Latest reply on May 11, 2009 7:33 AM by Ilya Shaikovsky

    InplaceSelect - value of component is previous when onchange

    shin hj Newbie

      hello.

      version : 3.3.1.CR2

      
      HtmlInplaceSelect input = (HtmlInplaceSelect) application.
      createComponent(HtmlInplaceSelect.COMPONENT_TYPE);
      String eventType = "onchange";
      
      input.setValueExpression("value", factory.createValueExpression( facesContext.getELContext(),"#{report.parameters." + key + "}", Object.class));
      
      HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
      ajaxSupport.setId("test_support");
      ajaxSupport.setEvent(eventType);
      ajaxSupport.setDisableDefault(true);
      ajaxSupport.setOncomplete("afterReportSearch(this)");
      ajaxSupport.setReRender(parentHandler.getReRenderTarget());
      ajaxSupport.setActionExpression(factory.createMethodExpression(
       facesContext.getELContext(),
       "#{reportViewer.searchReport}", Void.TYPE,
       new Class[] {}));
      
      
      
      when value change, component has the value( -> #{report.parameters." + key + "}" ) what is previous value in action ( -> #{reportViewer.searchReport} ).
      
      


        • 1. Re: InplaceSelect - value of component is previous when onch
          shin hj Newbie

           

          "hjshin" wrote:
          hello.

          version : 3.3.1.CR2

          
          HtmlInplaceSelect input = (HtmlInplaceSelect) application.
          createComponent(HtmlInplaceSelect.COMPONENT_TYPE);
          String eventType = "onchange";
          
          input.setValueExpression("value", factory.createValueExpression(facesContext.getELContext(),
          "#{report.parameters." + key + "}", Object.class));
          
          HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
          ajaxSupport.setId("test_support");
          ajaxSupport.setEvent(eventType);
          ajaxSupport.setDisableDefault(true);
          ajaxSupport.setOncomplete("afterReportSearch(this)");
          ajaxSupport.setReRender(parentHandler.getReRenderTarget());
          ajaxSupport.setActionExpression(factory.createMethodExpression(
           facesContext.getELContext(),
           "#{reportViewer.searchReport}", Void.TYPE,
           new Class[] {}));
          


          when value change, component has the value( -> #{report.parameters." + key + "}" ) what is previous value in action ( -> #{reportViewer.searchReport} ).





          • 2. Re: InplaceSelect - value of component is previous when onch
            shin hj Newbie

            when i change code of inplaceselect.js. it's working.

            
            ** original
            
            
             setValue : function(e, param) {
             var item = {};
             item.itemValue = this.getParameters(e,param,"value");
            
             if(this.showValueInView) {
             item.itemLabel = item.itemValue;
             } else {
             item.itemLabel = this.findLabel(this.comboList.itemsText,item.itemValue);
             }
            
             if (!item.itemLabel) {
             item.itemValue = this.currentItemValue;
             item.itemLabel = this.tempValueKeeper.value;
             }
            
             var value = this.valueKeeper.value;
             if (Richfaces.invokeEvent(this.events.onviewactivation, this.inplaceInput, "rich:onviewactivation", {oldValue : this.valueKeeper.value, value : item.itemValue})) {
             var proceed = true;
            
            ------------------------------>
            this part can move after value bind
            ----------------------------->
            
             if(item.itemLabel && value != item.itemValue) {
             proceed = Richfaces.invokeEvent(this.events.onchange, this.inplaceSelect, "onchange", item.itemValue);
             }
             }
            
            ------------------------------>
            
             if(proceed) {
             this.endEditableState();
            
             if (!item.itemValue || item.itemValue.blank()) {
             item.itemValue = "";
             }
            
             if (!item.itemLabel || item.itemLabel.blank()) {
             item.itemLabel = this.attributes.defaultLabel;
             }
            
             this.valueKeeper.value = item.itemValue;
             this.currentText = item.itemLabel;
             this.tempValueKeeper.value = item.itemLabel;
            
             if (item.itemValue != this.value) {
             this.startChangedState();
             } else {
             this.startViewState();
             }
            
             if (this.events.onviewactivated) {
             this.inplaceInput.fire("rich:onviewactivated", {oldValue : value, value : this.valueKeeper.value});
             }
            
             } else {
             this.cancel();
             }
            
            --------------------------------> here
            
             },
            
            
            




            
            ** update
            
            
             setValue : function(e, param) {
             var item = {};
             item.itemValue = this.getParameters(e,param,"value");
            
             if(this.showValueInView) {
             item.itemLabel = item.itemValue;
             } else {
             item.itemLabel = this.findLabel(this.comboList.itemsText,item.itemValue);
             }
            
             if (!item.itemLabel) {
             item.itemValue = this.currentItemValue;
             item.itemLabel = this.tempValueKeeper.value;
             }
            
             var value = this.valueKeeper.value;
             if (Richfaces.invokeEvent(this.events.onviewactivation, this.inplaceInput, "rich:onviewactivation", {oldValue : this.valueKeeper.value, value : item.itemValue})) {
             var proceed = true;
            
            
             if(proceed) {
             this.endEditableState();
            
             if (!item.itemValue || item.itemValue.blank()) {
             item.itemValue = "";
             }
            
             if (!item.itemLabel || item.itemLabel.blank()) {
             item.itemLabel = this.attributes.defaultLabel;
             }
            
             this.valueKeeper.value = item.itemValue;
             this.currentText = item.itemLabel;
             this.tempValueKeeper.value = item.itemLabel;
            
             if (item.itemValue != this.value) {
             this.startChangedState();
             } else {
             this.startViewState();
             }
            
             if (this.events.onviewactivated) {
             this.inplaceInput.fire("rich:onviewactivated", {oldValue : value, value : this.valueKeeper.value});
             }
            
             } else {
             this.cancel();
             }
            
             if(item.itemLabel && value != item.itemValue) {
             proceed = Richfaces.invokeEvent(this.events.onchange, this.inplaceSelect, "onchange", item.itemValue);
             }
             }
            
             },
            
            


            • 3. Re: InplaceSelect - value of component is previous when onch
              Ilya Shaikovsky Master

              inplace components has special events for processing the new value or checking the state changing..

              onviewactivated/oneditactivated

              onviewactivation/oneditactivation

              • 4. Re: InplaceSelect - value of component is previous when onch
                shin hj Newbie

                hello.

                when i use onviewactivated event,

                it's submitted(changed) with click the inplaceselect(i click the component for show), not with the value change.

                how can i submit when the value of the inplaceselect change only.


                sorry about poor english.
                thanks.

                • 5. Re: InplaceSelect - value of component is previous when onch
                  Ilya Shaikovsky Master

                  http://livedemo.exadel.com/richfaces-demo/richfaces/inplaceSelect.jsf

                  see last sample. do not pay attention to custom buttons. It will works the same without them.

                  • 6. Re: InplaceSelect - value of component is previous when onch
                    shin hj Newbie

                    hi,

                    could u test this..

                    component: inplaceselect
                    control : visible = false
                    event: onviewactivated
                    action: some method in java(ex: searchReport)

                    test : click the component and show list(suggestionbox) and then just click another part for close the list(suggestionbox) not select value. at this time(just close the list) act searchReport method.

                    i think view activated...so event happens.

                    i want some action when the value changed.
                    in this case may i use onchange event??? but i cound not use the onchange event because when i use onchange event i get a previos value(see previous post)

                    thanks.

                    • 7. Re: InplaceSelect - value of component is previous when onch
                      Ilya Shaikovsky Master

                      you could define not action but valueChangeListener.. then it will be fired only on value changed. (but request will be still nivoked.)

                      or you could store the inplace value and check if it changed on onsubmit in order to prevent unnesessary request.

                      anyway you're right.. It not looks fine https://jira.jboss.org/jira/browse/RF-7079