14 Replies Latest reply on Aug 29, 2013 2:38 AM by User437258

    How to Update DetailVO Attributes?

    User437258

      I have a master-detail page that utilizes a parameterized pop-up to allows the user to update a detail record attribute.  Everything works great except for the saving of the change to the database.  Meaning when the user makes their selection on the pop-up the pop-up PFR is invoked and the base page PR method is invoked.  In the base page PR I get the detailVO row using the masterVO accessor that returns a RowIterator that I use to find the detailVO row that should be updated and I update the attribute.  The base page is refreshed and I see the change in the page but the database is not updated to reflect the change in the model that is seen on the page.

       

      When I set a masterVO row attribute using the masterVO instance I obtain in the base page PR method this succeeds in updating the database record.  So it seems to be something to do with the detailVO attributes.  But I've gone as far as I know how since the page is reflecting the change to the model and I am issuing a commit using the am.getDBTransaction().commit().

       

      Please help.

       

      Thank you

        • 1. Re: How to Update DetailVO Attributes?
          Shddn

          Hi,

           

          Is View Object used in pop up oaf pafe is entity object based view object ?

           

          Regards

           

          Shobhit S

          • 2. Re: How to Update DetailVO Attributes?
            User437258

            The VO used in the pop up is a view only VO.  The VO used in the detail VO is entity based and I can update the attributes in the form manually but not programatically.  I can even update one attribute via the parameterized popup and the base page PR method, see this reflected in the page, manually update a field in the same detail record, submit the form via an "Apply" button, and see the manual update saved to the database but the programatically changed attribute is not updated in the database but the page still reflects the programatic change.  Very strange!

             

            Thank you

            • 3. Re: How to Update DetailVO Attributes?
              Shddn

              See

               

              Once you execute ViewObject query the data is refreshed from DB. I cannot understand what you mean by programatically and manually. Are you calling some update statement when you mean by manually.

               

              Can you please explain in detail

               

              Regards

               

              Shobhit S

              • 4. Re: How to Update DetailVO Attributes?
                User437258

                The manual update is done by manually typing in a value into a field in a detail record in the browser window and pressing the Apply button.  This method results in the newly entered value being saved to the database.  So this is what you might consider a normal method for entering and saving data.

                 

                The programatic method is done in the PR method of the base page's controller.  Please excuse all of the non controller code.  I just want to get this working before I refactor to the proper levels.

                 

                    if ("SelectOperator".equals(event)) {

                        // operator popup returned with user selection

                        String operator = (String)pageContext.getSessionValue("Operator"); // get session value set by popup controller

                        String ruleId = (String)pageContext.getSessionValue("RuleId"); // get session value set by popup controller

                        System.out.println("base operator = " + operator);

                        System.out.println("base ruleId = " + ruleId);

                         // tried setting prepared for execution on detail vo although this may not be the right VO.  getting detail VO via master VO iterator method below

                        XxmclApValidatorSetRevRulesVOImpl vo = am.getXxmclApValidatorSetRevRulesVO1();

                        vo.executeQuery();

                        if (vo.isPreparedForExecution()) {

                            System.out.println("vo.isPreparedForExecution is true");

                        }

                        Integer rowCount = vo.getRowCount(); // initializes the vo for the getFirstFilteredRow call.  Without this I can't get the row next.

                        Row row = vo.getFirstFilteredRow("RuleId",new DBSequence(new Integer(ruleId)));

                        System.out.println("current Row.getAttribute Operator1 = " + row.getAttribute("Operator1"));

                        XxmclApValidatorSetRevsVOImpl vo1 = (XxmclApValidatorSetRevsVOImpl)am.getXxmclApValidatorSetRevsVO1(); // get master VO from AM

                        XxmclApValidatorSetRevsVORowImpl row1 = (XxmclApValidatorSetRevsVORowImpl)vo1.getFirstFilteredRow("RevisionNumber",new Number(1)); // get correct master row, will need to add another session value to get the revision number if this works

                        RowIterator rulesIterator = row1.getXxmclApValidatorSetRevRulesVO(); // get rules row iterator from master VO row

                        while (rulesIterator.hasNext()) {

                //            if (rulesIterator.next().getAttribute("RuleID") == (new DBSequence(new Integer(ruleId)))) {

                //              System.out.println("found rule in iterator");

                                Row row2 = rulesIterator.next();

                                row2.setAttribute("Operator1",operator); // set the value of the rules detail record using session value

                                am.getDBTransaction().commit(); // not committing model change to DB but change is visible in page

                //            }

                        }

                 

                Thanks again

                • 5. Re: How to Update DetailVO Attributes?
                  Shddn

                  Hi There

                   

                  Sorry for a late reply.. Just wanted to confirm XxmclApValidatorSetRevRulesVO is EO based VO right ?

                   

                  Regards

                   

                  Shobhit S

                  • 6. Re: How to Update DetailVO Attributes?
                    User437258

                    Yes.  XxmclApValidatorSetRevRulesVO is based upon XxmclApValidatorSetRulesEO.

                     

                    Thank you very much.

                    • 7. Re: How to Update DetailVO Attributes?
                      Shddn

                      and Operator1 is calculated attribute of XxmclApValidatorSetRevRulesVO based on EO attribute ?

                       

                      Regards

                       

                      Shobhit S

                      • 8. Re: How to Update DetailVO Attributes?
                        User437258

                        Operator1 maps not a calculated attribute of the VO.  Operator1 maps directly to an attribute of the EO that is mapped directly to a database column.

                         

                        I have tried updating other detail VO attributes as well and they will all update in the model but will not be saved to the database.

                        • 9. Re: How to Update DetailVO Attributes?
                          Shddn

                          Please share the code where you init XxmclApValidatorSetRulesEO

                           

                          Regards

                           

                          Shobhit S

                          • 10. Re: How to Update DetailVO Attributes?
                            User437258

                            I don't have any explicit initialization for the EO object.  I believe the query on the master table is enough to initialize the master VO/EO and the detail VO/EO.  Although I'm probably (hopefully) wrong.

                             

                            Thank you

                            • 11. Re: How to Update DetailVO Attributes?
                              Shddn

                              this is probably done when you have AO between your child and master EO

                               

                              Regards

                               

                              Shobhit S

                              • 12. Re: How to Update DetailVO Attributes?
                                User437258

                                I have the AO object to relate the two EO's.  Everything in the page (master records to detail records relationship, saving any entered data, etc.) works except for programatic updates to the detail VO attributes.  And they work to a degree.  Meaning they are reflected in the page.  They just are not saved to the database.

                                 

                                Thank you

                                • 13. Re: How to Update DetailVO Attributes?
                                  User437258

                                  I found that if I change the detail VO from Expert mode to not Expert mode the changes I make programatically are persisted to the database.  I've replaced the expert mode defined VO with a new VL to get this attribute (it's a lookup meaning).  Now I just need to learn how to get this new LookupVO meaning attribute to replace the existing page component that supports the popup I created.

                                  • 14. Re: How to Update DetailVO Attributes?
                                    User437258

                                    I also found that for a given database record, if you have multiple advanced table components (one master, one detail, and another for the detail VO but not an inner advanced table of the master) for the same VO instance there are multiple VORowImpl instances.  Not  what I expect.  See for yourself by creating the page with the 3 advanced tables and writing code in your controller to 1) find a detail row via the master VO accessor and 2) find the same record by getting an instance of the detail VO.  If you set a transient attribute defined in the VO using each of these row instances but using different values the page will show the two values on the two separate record displays that I would expect would be the same.