14 Replies Latest reply: Nov 27, 2012 11:39 AM by Jai Om-Oracle RSS

    Resetting current row after BTF method call

    Jai Om-Oracle
      Hello,

      I am using Jdev 11.1.1.6. Technology used in project is ADF BC and ADF Faces.

      I have a fragment based BTF. The fragment is based on .jspx template.
      Runtime scenario is that the fragment displays data in read-only table with af:commandToolbarButton implemented in panelCollection toolbar facet.
      The button is calling AM method (via PageDef methodAction) using taskflow method call. Input passed to method call is key column value from current row.
      The problem is that after the call, it is resetting the current row in the table to the first row. I would like to keep the current row selected.

      How do I achieve this? I would appreciate Declarative/Minimal Programming solution. Let me know if more info is required here.

      af:table has following properties, partialTriggers is referencing af:commandToolbarButton Id :
      <af:table value="#{bindings.VO1.collectionModel}"
      var="row" rows="#{bindings.VO1.rangeSize}"
      first="#{bindings.VO1.rangeStart}"
      fetchSize="#{bindings.VO1.rangeSize}"
      rowBandingInterval="0"
      filterModel="#{bindings.VO1Query.queryDescriptor}"
      queryListener="#{bindings.VO1Query.processQuery}"
      filterVisible="false" varStatus="vs"
      selectedRowKeys="#{bindings.VO1.collectionModel.selectedRow}"
      selectionListener="#{bindings.VO1.collectionModel.makeCurrent}"
      rowSelection="single" id="tbl1"
      displayRow="selected"
      autoHeightRows="5"
      contentDelivery="immediate"
      columnSelection="multiple"
      partialTriggers="::ctb1">

      Thanks,
      Jai
        • 1. Re: Resetting current row after BTF method call
          kdario
          I suppose that you execute query or rollback in your method so current row is lost.
          Try to restore current row at the end of your method, something like:
          Row currRow = vo.getCurrentRow();
          .
          .
          vo.setCurrentRow(currRow)
          Dario
          • 2. Re: Resetting current row after BTF method call
            Jai Om-Oracle
            Hello Dario,

            Thanks for responding to my post.

            I did not realize until I saw your response that this is occurring only in the case of exception thrown by DB package. It's just that, I started with testing the error part first to see if it's working or not.
            After your seeing your response, I tried with success scenario and it kept the current row intact.
            So yes, AM method is actually catching the SQLException and then issue this.getDBTransaction().rollback();, which probably is causing this behavior.

            I don't want to route my AM call through backing bean and would like to keep it as PageDef methodAction call.
            Is there something in taskflow that can take care this i.e. store the current row and in case of failure set it back? OR Is there anything I can do to not loose current row in case of rollback?

            Thanks,
            Jai
            • 3. Re: Resetting current row after BTF method call
              kdario
              Well, actually I suggested that you add this code in AM method and not in backing bean :)
              Also in view object exposed methods you have setCurrentRowWithKey, but I'm not sure how you can call this declaratively after first method. Maybe you can put row key to pageFlowScope, then navigate to MethodCall activity and then return to page, but this is overkill :)

              Dario
              • 4. Re: Resetting current row after BTF method call
                Jai Om-Oracle
                Hi,

                I tried your suggestion to put the code in AM method to get the current row in the beginning and then set it back in VO after exception.
                The problem is that current row is coming as NULL.
                I am accessing the current row as this.getVO.getCurrentRow() inside the AM method.
                This VO instance is exposed on current AM and then AM is exposed on another ParentAM (which is root). On view controller side, we are using this VO instance as Root.AM.VO

                Anything missing here?

                Thanks,
                Jai
                • 5. Re: Resetting current row after BTF method call
                  Jai Om-Oracle
                  Anybody? Any thoughts, why current Row is coming NULL.
                  I also tried:
                  Row currentRow = this.findViewObject("Root.AM.VO").getCurrentRow();
                  and
                  Row currentRow = this.findViewObject("VO").getCurrentRow();

                  But both statement above returns currentRow as null.

                  Thanks,
                  Jai
                  • 6. Re: Resetting current row after BTF method call
                    kdario
                    Are you sure that current row is null ?
                    Maybe is null after rollback (because this is reference to existing row and not deep copy)?
                    If this is a case, then use findAndSetCurrentRowByKey() method.
                    for example: http://adfcodebits.blogspot.com/2010/09/bit-23-using-findandsetcurrentrowbykey.html

                    Dario
                    • 7. Re: Resetting current row after BTF method call
                      Jai Om-Oracle
                      Hello Dario,

                      Now, I have tested this in simple application with VO exposed on nested AM. I created a simple method "TestVOCurrentRow" and there I am trying to get current row using all these variations mentioned in previous post.
                      There is no other function performed. It's just simple AM method call.

                      If I expose the same VO on Root AM and then check the current row in AM method, it perfectly gives the UI selected row.
                      So I guess the issue here is nested AM and I am not sure what am I doing wrong to find the view object or get the current row.

                      Any thoughts on getting the current row from nested AM VO instance?

                      Thanks,
                      Jai
                      • 8. Re: Resetting current row after BTF method call
                        kdario
                        I just tried this in jdev 11.1.2.3 (child AM expose custom method)

                        This doesn't work(throws NPE):
                        Row currentRow = this.getEmployeesVO().getCurrentRow();
                        this.getTransaction().rollback();
                        this.getEmployeesVO().setCurrentRow(currentRow);
                        but, this work:
                        Row currentRow = this.getEmployeesVO().getCurrentRow();
                        Key key = this.getEmployeesVO().getCurrentRow().getKey();
                        int rangePosOfCurrentRow = this.getEmployeesVO().getRangeIndexOf(currentRow);
                        int rangeStartBeforeQuery = this.getEmployeesVO().getRangeStart();
                                
                        this.getTransaction().rollback();
                                
                        this.getEmployeesVO().setRangeStart(rangeStartBeforeQuery);
                        this.getEmployeesVO().findAndSetCurrentRowByKey(key, rangePosOfCurrentRow);
                        Dario
                        • 9. Re: Resetting current row after BTF method call
                          Jai Om-Oracle
                          Thanks for testing it out in Jdev 11.1.2.3.
                          My Jdev version is 11.1.1.6 and current row from nested AM VO instance is always coming as NULL.

                          As I mentioned earlier, I get correct current row when I expose the VO on Root AM itself but not when it is on child AM.
                          Level of nesting is not affecting the scenario. I tested it with 2 level nesting and 1 level nesting, same result in both cases.
                          It finds the view object in all scenarios but not the current row.

                          So not sure if this is something to do with Jdev version OR I have something not proper on my nested AM.
                          Following is the code in my child AM method. You can see different ways to get the current row but all returns null:
                              public void TestVOCurrentRow() {
                                  Row currentRow = null;
                                  currentRow = this.getVO().getCurrentRow();
                                  if(currentRow == null)
                                     currentRow = this.findViewObject("VO").getCurrentRow();
                                  
                                  if(currentRow == null)
                                      currentRow = this.findViewObject("Root.AM1.VO").getCurrentRow();
                                  
                                  if(currentRow == null){
                                      currentRow = this.findApplicationModule("Root").findApplicationModule("AM1").findViewObject("VO").getCurrentRow();
                                  }
                              
                                  if(currentRow == null){
                                      System.out.println("current row is null");
                                  }
                                  else{
                                      System.out.println("Attribute Value " + currentRow.getAttribute("xyz"));
                                  }
                              }
                          Thanks,
                          Jai
                          • 10. Re: Resetting current row after BTF method call
                            Puthanampatti
                            For your initial post, Try setting TF behaviour to Use Existing Transaction if Possible & check Share data controls with calling task flow.

                            btw, I hope you have changed your pageDef methodAction bindings to reflect rootAM changes.

                            Root Application Module issue
                            • 11. Re: Resetting current row after BTF method call
                              Jai Om-Oracle
                              Hello,

                              Thanks for responding to my post and sharing info.
                              Transaction scope is not making any difference. I have tried with "Use Existing Transaction, if possible with Share data control" and "Always Begin New Transaction".

                              Yes, I changed the AM methodAction bindings. I am debugging and it is going to method in Child AM but returns current row as null.

                              Can anyone confirm it to be working with Jdev 11.1.1.6?

                              Thanks,
                              Jai
                              • 12. Re: Resetting current row after BTF method call
                                Puthanampatti
                                What did you use in "InstanceName" in the pafeDef bindings?

                                try, Refresh="prepareModelIfNeeded" in the iterator binding.
                                • 13. Re: Resetting current row after BTF method call
                                  Jai Om-Oracle
                                  Hi,

                                  Setting the Refresh="prepareModelIfNeeded" did not help. Same result and current row is still null.

                                  My Iterator binding code in PageDef is:
                                  <iterator Binds="Root.AM1.VO" RangeSize="25"
                                                DataControl="TestAMDataControl" id="VOIterator"/>
                                  My methodAction binding code in PageDef is:
                                      <methodAction id="TestVOCurrentRow" RequiresUpdateModel="true"
                                                    Action="invokeMethod" MethodName="TestVOCurrentRow"
                                                    IsViewObjectMethod="false" DataControl="TestAMDataControl"
                                                    InstanceName="TestAMDataControl.dataProvider.Root.AM1"
                                                    ReturnName="data.TestAMDataControl.methodResults.TestVOCurrentRow_TestAMDataControl_dataProvider_Root_AM1_TestVOCurrentRow_result"/>
                                  Thanks,
                                  Jai
                                  • 14. Re: Resetting current row after BTF method call - Solved
                                    Jai Om-Oracle
                                    Thanks everyone for your valuable inputs. I solved my initial issue of setting current row in BTF after method call resulting in "Rollback".
                                    Special thanks to Dario who gave this suggestion of "setCurrentRowWithKey".

                                    Here is what I did:
                                    1. Added af:setPropertyListener to button to preserve the current row key using following code:
                                    <af:setPropertyListener type="action" from="#{bindings.VOIterator.currentRowKeyString}"
                                                                                          to="#{pageFlowScope.voCurrentRowKeyString}"/>
                                    2. Added a methodAction to my BTF by drag-drop "setCurrentRowWithKey" from data control VO operations. PageDef of this methodAction has:
                                        <action IterBinding="VOIterator" id="setCurrentRowWithKey"
                                                RequiresUpdateModel="false" Action="setCurrentRowWithKey">
                                          <NamedData NDName="rowKey" NDValue="#{pageFlowScope.voCurrentRowKeyString}" 
                                                     NDType="java.lang.String"/>
                                        </action>
                                    3. Router activity is already checking for success and failure return value. Routed the call to this new method [setCurrentRowWithKey] for failure case and BINGO...It preserves the current row after Rollback.

                                    Not sure if this is the ideal way but it works. Please share if there is any better way.

                                    Issue of current row coming null in nested child AM still exist but I'll start a fresh thread for that and share the link here.

                                    Thanks,
                                    Jai