4 Replies Latest reply: Sep 13, 2013 6:11 AM by Subramanian Meyyappan RSS

    Error message doesn't show when I add rollback in the code

    nat

      Hi,

      I am using jDeveloper 11.1.2.4.0.

      I have a confirmation dialog popup when users commit data. I also created an Entity Validators in business rules of EO. When the validation is not passed, the error message should display and then transaction should be rollbacked automatically. However, the error message dosn't shown if I put rollback operation in my code.

      I wrote the code in a dialogListener of the confirmation dialog. Here is the code....

       

          public void confirmDialogListener(DialogEvent dialogEvent) {

              if (dialogEvent.getOutcome().name().equals("ok")) {

                  BindingContainer bindings = getBindings();

                  OperationBinding operationBinding = bindings.getOperationBinding("Commit");

                  operationBinding.execute();

                  if (!operationBinding.getErrors().isEmpty()) {

                      BindingContainer bindings1 = getBindings();

                      OperationBinding operationBinding1 = bindings1.getOperationBinding("Rollback");

                      operationBinding1.execute();

                  }

              }

          }

       

      Please suggest what I should do in order to keep the error message displayed and still be able to rollback transaction automatically.

      Thanks.

      nat

        • 1. Re: Error message doesn't show when I add rollback in the code
          Cvele_new_account

          Take a look at comments I made bellow:

          nat wrote:

           

          Hi,

          I..

           

              public void confirmDialogListener(DialogEvent dialogEvent) {

                  if (dialogEvent.getOutcome().name().equals("ok")) {

                      BindingContainer bindings = getBindings();

                      OperationBinding operationBinding = bindings.getOperationBinding("Commit");

                      operationBinding.execute();

                      if (!operationBinding.getErrors().isEmpty()) {


                         // TAKE A ERROR MESSAGE HERE SOMEHOW

                          BindingContainer bindings1 = getBindings();

                          OperationBinding operationBinding1 = bindings1.getOperationBinding("Rollback");

                          operationBinding1.execute();
                          // AFTER ROLLBACK, SHOW JSF FACES ERROR MESAGES (IF PRESENTS)

                      }

                  }

              }

           

          Please suggest what I should do in order to keep the error message displayed and still be able to rollback transaction automatically.

          Thanks.

          nat

          • 2. Re: Error message doesn't show when I add rollback in the code
            nat

            I put the following code in " // TAKE A ERROR MESSAGE HERE SOMEHOW"...

                                List<JboException> list = oprCommit.getErrors();

                                String msg = null;

                                for (int i = 0; i < list.size(); i++) {

                                    if (i == 0) {

                                        msg = list.get(i).getMessage();

                                    } else {

                                        msg = msg + "\n"+

                                                list.get(i).getMessage();

                                    }

                                }

            and put the following code in "// AFTER ROLLBACK, SHOW JSF FACES ERROR MESAGES (IF PRESENTS)"...

                                if (msg != null) {

                                FacesMessage fm = new FacesMessage(msg);

                                fm.setSeverity(FacesMessage.SEVERITY_ERROR);

                                FacesContext context = FacesContext.getCurrentInstance();

                                context.addMessage(null, fm);

                                }

            I got 2 problems....

            1. The error message is not the message I set in the business rule. Instead it showed JBO-27023: Failed to validate all rows in a transaction. Before modifying the code, it showed the correct error message. I am not sure if I get message from the correct method.

            2. The message displayed on top of the confirmation popup and when I click ok, the confirmation popup doesn't close. I try to hide the confirmation popup after context.addMessage command, the message displayed just a second and disappeared...

            • 3. Re: Error message doesn't show when I add rollback in the code
              Cvele_new_account

              Ok.

               

              Why not just leave the user to do rollback ?

              In other words, when dialog "OK" event occurs, try to do just Commit.
              In this way, you are  giving the user a chance to correct the error.

              And perform rollback just in case of dialog  "Cancel" event...huh ?

              • 4. Re: Error message doesn't show when I add rollback in the code
                Subramanian Meyyappan

                Just to do the validation in UI

                public String save_action() {

                        BindingContainer bind = getBindings();

                        DCIteratorBinding dciter = (DCIteratorBinding)bind.get("EmployeesView1Iterator");

                        Number num = (Number)dciter.getViewObject().getCurrentRow().getAttribute("Salary");

                        if(num.intValue() < 1000)

                        {

                            String msg ="Salary should be greater than 1000!";

                            FacesMessage message = new FacesMessage(msg); message.setSeverity(FacesMessage.SEVERITY_ERROR);

                            FacesContext fc = FacesContext.getCurrentInstance();

                            fc.addMessage(null, message);

                            OperationBinding operationBinding = c.getOperationBinding("Rollback");

                            Object result = operationBinding.execute();

                        }

                        else{

                        OperationBinding operationBinding = c.getOperationBinding("Commit");

                        Object result = operationBinding.execute();

                        if (!operationBinding.getErrors().isEmpty()) {

                        }

                        else{

                        }

                        }   

                        return null;

                    }

                Its works. if the validation fails it will rollback.

                 

                I tried the same in Entity validator method also

                if the validation fails roll back it.

                more or less it working as same.

                 

                we can this achieve over task flow also.

                But i didn't know i reached your desired output or not.