APEX - Creating a page with multiple forms linked to multiple related tables… that all submit with one button?

后端 未结 2 1042
野趣味
野趣味 2020-12-05 21:09

I have two tables in APEX that are linked by their primary key. One table (APEX_MAIN) holds the basic metadata of a document in our system and the other (APEX_DATES) holds i

相关标签:
2条回答
  • 2020-12-05 21:43

    It is a limitation of the built-in Apex forms that you can only have one automated row fetch process per page, unfortunately. You can have more than one form region per page, but you have to code all the fetch and submit processing yourself if you do (not that difficult really, but you need to take care of optimistic locking etc. yourself too).

    Splitting one table's form over several regions is perfectly possible, even using the built-in form functionality, because the region itself is just a layout object, it has no functionality associated with it.

    Building forms manually is quite straight-forward but a bit more work.

    Items

    These should have the source set to "Static Text" rather than database column.

    Buttons

    You will need button like Create, Apply Changes, Delete that submit the page. These need unique request values so that you know which table is being processed, e.g. CREATE_EMP. You can make the buttons display conditionally, e.g. Create only when PK item is null.

    Row Fetch Process

    This will be a simple PL/SQL process like:

    select ename, job, sal
    into :p1_ename, :p1_job, :p1_sal
    from emp
    where empno = :p1_empno;
    

    It will need to be conditional so that it only fires on entry to the form and not after every page load - otherwise if there are validation errors any edits will be lost. This can be controlled by a hidden item that is initially null but set to a non-null value on page load. Only fetch the row if the hidden item is null.

    Submit Process(es)

    You could have 3 separate processes for insert, update, delete associated with the buttons, or a single process that looks at the :request value to see what needs doing. Either way the processes will contain simple DML like:

    insert into emp (empno, ename, job, sal)
    values (:p1_empno, :p1_ename, :p1_job, :p1_sal);
    

    Optimistic Locking

    I omitted this above for simplicity, but one thing the built-in forms do for you is handle "optimistic locking" to prevent 2 users updating the same record simultaneously, with one's update overwriting the other's. There are various methods you can use to do this. A common one is to use OWA_OPT_LOCK.CHECKSUM to compare the record as it was when selected with as it is at the point of committing the update.

    In fetch process:

    select ename, job, sal, owa_opt_lock.checksum('SCOTT','EMP',ROWID)
    into :p1_ename, :p1_job, :p1_sal, :p1_checksum
    from emp
    where empno = :p1_empno;
    

    In submit process for update:

    update emp
    set job = :p1_job, sal = :p1_sal
    where empno = :p1_empno
    and  owa_opt_lock.checksum('SCOTT','EMP',ROWID) = :p1_checksum;
    
    if sql%rowcount = 0 then
        -- handle fact that update failed e.g. raise_application_error
    end if;
    
    0 讨论(0)
  • 2020-12-05 21:43

    Another, easier solution for the fetching part is creating a view with all the feilds that you need.

    The weak point is it that you later need to alter the "submit" code to insert to the tables that are the source for the view data

    0 讨论(0)
提交回复
热议问题