5 Replies Latest reply: Jul 24, 2013 1:40 AM by BAO.SZ Branched to a new discussion. RSS

    Why the page cannot refresh correctly after making checkbox selection?

    BAO.SZ

      Hi,experts:

      In jdev 11.1.2.3,

      I  drag and drop a data control to create an adf read-only table in a jsff page, and change one of the table's column (sel) into a check box,

      and this column is based on a trasient attribute in the underlying VO.

       

      The requirement is:

      If the user select the table row (have the checkbox been checked), then set two other columns in the same row to be -1, otherwise to be 0.

      and the table be refreshed to show the new changes immediately.

       

      What I have done is:

      When the checkbox is selected, a method (selectBillCheckBox) in the back bean will be called.

      The page codes is like this:

      <af:selectBooleanCheckbox value="#{row.bindings.sel.inputValue}" label="#{row.bindings.sel.label}"

                                        shortDesc="#{bindings.BillVO4Pending1.hints.sel.tooltip}" id="sel"

                                        valueChangeListener="#{multiSelectBean.selectBillCheckBox}" autoSubmit="true"/>

      The backing bean code is like this:

          public void selectBillCheckBox(ValueChangeEvent valueChangeEvent) {
              // Add event code here...
            
              BindingContext bindingctx=BindingContext.getCurrent();            
              BindingContainer binding=bindingctx.getCurrentBindingsEntry();  
              DCBindingContainer bindingsImpl = (DCBindingContainer) binding;  
              DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("BillVO4Pending1Iterator");  
                                    
              ViewObject vo=dciter.getViewObject();  
              Row rr=null;                  
              long rowc = vo.getEstimatedRowCount();
              if (rowc ==0){
                  rr=vo.first();  
               }
              else{
                  rr=vo.getCurrentRow();
              }
             
              if (valueChangeEvent.getNewValue().equals(true)) {
                  rr.setAttribute("Status", -1);
                  rr.setAttribute("IsValid", -1);
              } else {
                  rr.setAttribute("Status", 0);
                  rr.setAttribute("IsValid", 0);
              }
                 
              //This below line of code was told by Timo in a previos thread.

             //to submit chnages in page immediately to database

              valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());

              BindingContainer bindings = getBindings();      
              OperationBinding operationBinding =bindings.getOperationBinding("Commit");       
              operationBinding.execute();
              if (!operationBinding.getErrors().isEmpty()){
                  return;
              }            
              return;      
          }

       

       

      The issue is:

      Some time when a row (for example row of NO.2) is selected(the checkbox is checked), but the two columns( Status,IsValid ) will not be changed,

      and if I select another table row(for example row of NO.3),  changes for columns of this row will be showed in the page imediately.

      Then I select the previous row (NO.2) the second time, and changes will be showed.

      This issue can be recured very oftenly.

       

      Can anyone help me to fix it?

      Thanks very much!

        • 1. Re: Why the page cannot refresh correctly after making checkbox selection?
          SudhanshuG

          Do component binding of table in backing or take component by traversing tree like

           

          valueChangeEvent.getComponent().getparent()... until u reach to table


          and add partial trigger.

          • 2. Re: Why the page cannot refresh correctly after making checkbox selection?
            BAO.SZ

            The issue is the strange behavior of checkbox selection:

            The checkbox selection cannot always work as defined.

            It seems as if user click the checkbox too quick to have the method been executed but the checkbox has been marked as selected.

             

            Has anyother one come up with this issue?

            Thanks.

            • 3. Re: Why the page cannot refresh correctly after making checkbox selection?
              Timo Hahn

              You are way to complicated. An easy way to avoid most of the in your bean method is to create attribute bindings for the attributes you want to change and use them from the bean to set the new values. There is no need to use the iterator to find the row as the framework does select the row and put the values onto the attribute bindings.

              // get the binding container

              BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();

               

              // get an ADF attributevalue from the ADF page definitions

              AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("test");

              attr.setInputValue("test");

               

               

              Timo

              • 4. Re: Why the page cannot refresh correctly after making checkbox selection?
                BAO.SZ

                Hi,Timo,

                Thank you for your helpful suggestions!

                 

                I wrote above bean java code after a blog, in fact, as a newbie to Java, I cannot wrote them by myself.

                ADF Table: Select multiple rows using check box.

                http://www.adftutorials.com/adf-table-select-multiple-rows-using-check-box.html

                 

                When I was mimicing these codes, there did some wonders in my mind: does it need so complex?

                But I had not enough knowledge to make the decision on the case.

                 

                For me, when writing java code or any other program language, include in Jdev, difficulties include:

                1. How to name a object/class?

                even in Jdev, in Bind Action Property->Create Managed Bean popup, when prompted to enter Bean Name/Class Name,

                it's not easy for me to make the decision, I mean, I'm afraid:

                what's a better name here? need the Bean name be same or different from the Class name?

                how to avoid conflicts with other bean name? etc.

                2. Where can I find object/interfaces/methods that can be used for? Do I need to write one by myself?

                Of course the Jdev IDE can give great help, for prompt choice list will be showed after enter a "." by object name.

                But, it's easy for a newbie like me to lose way in such a huge class hiearchy.

                3.How to organize/group objects/files?

                For example, how to organize/group EO/VO/LINK/AMs?

                It seems it's a easier work to write direct business logic with some "if-then-else" style codings in a defined code block,

                than to group/organize these objects.

                --Maybe this is the different work of a architect from a programmer?

                 

                So, I'd strongly prefer a declarative way to develop any functions.--

                There is a framework that will help me make less choices, including unneccessary namings, limit outside influences of current choices.


                For the current issue/task--set some other attributes' values after one attribute's value has been changed in a row of a VO,

                I think there will be a declarative way to do it: for a VO(id,sel boolean, Status integer, IsValid integer)

                1.set Status depend on sel,and default attribute as:

                if (sel == true)

                return 1

                else

                {

                if (sel == false)

                return 0

                else

                return null

                }

                2.set IsValid depend on Status, and default attributes as: Status.

                3.set all these three attributes updatable to Always.

                 

                If the above setting can work, then apparently, it's much simple than writing Java codes.

                 

                Unfortunately, these settings cannot work as desired. I don't know why--it should work!

                However, I have got to know how to get it as:

                How to set a VO's attribute value depend upon other attributes?

                 

                and by these declarative way, I have succeeded in ADF-tester:

                Select sel will change Status, IsValid.

                 

                But when test it in pages, after select checkbox(sel), an error msg will be raised:

                Error: This attribute is not a integer.

                I need some help here.


                When I wrote bean method according to Timo's suggestion as:

                ==============================================

                public void selectBillCheckBox(ValueChangeEvent valueChangeEvent) {
                // Add event code here...
                //TimoHahn 2013-7-22 上午3:33 (in response to BAO.SZ)
                // get the binding container

                 

                BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
                /*
                ControlBinding control = bindings.getControlBinding("Status");
                AttributeBinding status = (AttributeBinding) control;
                status.setInputValue(returnEvent.getReturnValue());
                */
                // get an ADF attributevalue from the ADF page definitions
                if (valueChangeEvent.getNewValue().equals(true)) {
                System.out.println(" sel=true setting... setAttribute:-1...bindings:: "+bindings);
                AttributeBinding status = (AttributeBinding)bindings.getControlBinding("Status");  
                AttributeBinding isvalid = (AttributeBinding)bindings.getControlBinding("IsValid");
                System.out.print(status + " ========================= " + isvalid);
                status.setInputValue(-1);
                isvalid.setInputValue(-1);
                } else {
                System.out.println(" sel != true setting... setAttribute:0 ");
                AttributeBinding status = (AttributeBinding)bindings.getControlBinding("Status");
                AttributeBinding isvalid = (AttributeBinding)bindings.getControlBinding("IsValid");
                System.out.print(status + " ========================= " + isvalid);
                status.setInputValue(0);
                isvalid.setInputValue(0);
                }

                 

                return;

                }

                ====================================================

                 

                I also found:

                System.out.print(status + " ========================= " + isvalid);

                will results:

                null=========================null

                What wrong with these codes?

                I need more help.

                 

                Thank you all!

                BAO

                 

                • 5. Re: Why the page cannot refresh correctly after making checkbox selection?
                  BAO.SZ

                  You are way to complicated. An easy way to avoid most of the in your bean method is to create attribute bindings for the attributes you want to change and use them from the bean to set the new values. There is no need to use the iterator to find the row as the framework does select the row and put the values onto the attribute bindings.

                  Even maybe on way to compicated, if there is no wrong in codes, than the software should behaviour consistently. Otherwise how can we trust on software?

                  Can anyone find what's wrong with above codes? (It's not real complex.)

                  or

                  Is it a possible bug for Jdev/ADF?

                   

                  Thanks.