Refresh the view after retrieving data using Edit Action

Hello, my friends,

I’m facing an issue to Refresh the screen and its data table after receiving data using Oracle JDBC and execute its query and save it in ArrayList. In the view controller (openDialog), there is an event called request action using data context to set data one by one (for loop) into the Data container, and everything going well and set the data successfully in the data container but when I click “save” one record would appear in the data table and after click refresh, all record will be reloaded.

Here is some sample for my code:
Service#
ArrayList outputString = new ArrayList<>();

            //step1 load the driver class
            Class.forName("oracle.jdbc.driver.OracleDriver");

            //step2 create  the connection object
            Connection con= DriverManager.getConnection("");

            //step3 create the statement object
            Statement stmt = con.createStatement();

            //step4 execute query
            ResultSet rs = stmt.executeQuery("")

           while(rs.next()){
           Dto dto = new Dto();
                    getDto.setId(rs.getString(1));
                    getDto.setName(rs.getString(2));
            }

            //step5 close the connection object
            con.close();
            rs.close();

            return outputString;
           }

Controller#

 private DataContianer getData(Data request) {
        if (result != null) {
            for (int i = 0; i < result.size(); i++) {
                request = dataContext.create(Data.class);
                request.setId(result.get(i).get_Id());
                request.setName(result.get(i).get_Name());
}

 @ Subscribe("requestAction")
 private void onRequestAction(Action.ActionPerformedEvent event){
            String Number = numberFeild.getValue();
            Boolean callingStatus = false;
            DataContianer request = new DataContianer();
            if (criteriaField.getValue() == "ID") {
                result = GetService.GetDataById(Number);
                if(result.size() != 0) {
                    getDataContianer(request);
                    callingStatus = true;
                }
            }
If (callingStatus) {
            getScreenData().getDataContext().commit();
            getScreenData().loadAll();
            closeWithDiscard();
    }
    }

This is a part of my code, and as you see that I’m doing loadAll and getDataContext.Comment but I’m getting one empty record and one record appears instead of 18 records.

Please help me first to refresh the Data table in the view then I need some advice to my code and is there another professional way to execute the oracle query and insert data directly to the data container without all there loops.

One thing that I didn’t mention I re-edit the screen of Editor to have different control and we make create action for requesting and retrieving data.

All the best,

Hi Bakr,

It looks like you might use CUBA in a bit different way. Usually, you do not need to use JDBC directly in CUBA, but use JPA facilities like entity manager or data manager.

As for the screen, please consider installing a proper delegate to your screen’s data loader to load data from the service directly into screen’s data container.

1 Like

Hi Andrey,

Thanks for your clarification, I read the developer manual several times but I didn’t achieve the write execution for one of these JPA facilities, so could you please explain how can I apply the entity manager and data manager in my above code.

Many thanks,

Hi,

I’m not sure what you’re going to achieve by the code above. Let me try to explain and please correct me if I’m wrong.

  1. You have a service that returns a list of Dto class. And these DTO’s are fetched from a DB with a query.
  2. You want to use the service above to show DTO’s on a screen.

Questions:

  1. Do you plan to modify DTO’s in the DB?
  2. Do you use any extra conditions from the screen to fetch data?

Hey Andrey,

So sorry to be late, I was so busy in another project:

  1. You have a service that returns a list of Dto class. And these DTO’s are fetched from a DB with a query. (correct)

  2. You want to use the service above to show DTO’s on a screen. (correct)

Questions:

  1. Do you plan to modify DTO’s in the DB?
    (yes, I do, but I don’t have any problem with this, I did another service doing that by posting an updated data using API, and the API receiving the variables one by one)

  2. Do you use any extra conditions from the screen to fetch data?
    Yes, but just I want to execute three different queries and each one return different value, and what I did is created lookup field (dropdown list) and each one would execute a different query.

Thanks.

Hi Bakr,

Please find a small example attached. It loads Dto entities from a database and can reload data based on a value entered in a text field. untitled.zip (86.7 KB)

Hope this will help.

1 Like