Forum Stats

  • 3,770,163 Users
  • 2,253,079 Discussions
  • 7,875,350 Comments

Discussions

Multiple read-only forms using the same page item

MrE-Oracle
MrE-Oracle Member Posts: 12 Employee

Hello,

I have a page that shows the details of an object, referenced by its ID.

I haven't found a better way to show data in read only format than to use a FORM region and initializing the form with a page item for the ID which is passed to the page.

(If there is another way that's simple, I'd love to hear)

The form technique works well when there is only 1 form and the page item is the key to the table, but I have multiple of these read-only forms on my page, as I reference multipel pieces of data from different tables. They all refer to the object with the same key (page item), but I can't have multiple page_items with the same name so I had to alias the key in the query so it has a different name in the form.

When creating a single form, the initialize form process is also created automatically, and that works well for a single form, however after I alias my key to get a different page Item name in each form, the init does not work and my data does not show.

I had to create a second identical init process for the same form region for this to work (i.e. initialize the form twice)

I am passing the ID page Item to the query for the form.

Not sure if this is a bug or how to make this work with one init process only.

Is there a simpler way to show multiple pieces of data from different tables into read-only / display regions, without going to the custom HTML type display?

Tagged:

Answers

  • InoL
    InoL Member Posts: 9,347 Gold Crown

    I can only assume that you are trying to get data from multiple tables because there is a foreign key relation? What exactly is the data model here?

    A form with a table/view as source has an additional WHERE clause. Can you use that? Something like

    fk_id = :p1_id

    This would normally retrieve multiple records, so I'm not sure why you are looking for multiple form regions instead of one form region with multiple IR or IG regions.

  • MrE-Oracle
    MrE-Oracle Member Posts: 12 Employee

    I'm using a WHERE clause to select the proper object in the table for each form (i.e. the form displays the details of the selected item.)

    I want to display different regions with different parts of the data. All tables use the same key to reference the same item's data.

    Let's say the key in each table is ID, and the page is page 2, and that I come from page 1 passing the ID as a URL parameter to page 2. I pass P2_ID to page 2

    With a single form on the page, without aliasing the column name, I get a form with a Page Item P2_ID automatically. If i create second form region without aliasing, it creates another P2_ID page item and that conflicts with the first one.

    So I need to alias the column. My SQL then goes like:

    SELECT ID as ID2, COL2, COL3 FROM MY_TABLE_1 WHERE ID = :P2_ID

    I use 'Page Items to submit' P2_ID form for the SQL section.

    I now have a form with P2_ID2 as the page item, and a 'Initialize form' process, which does not initialize the data. (<--- this is the problem here)

    If i create a second identical 'initialize form' process, then my data gets pulled into the form and shows when getting to page 2 from page 1 passing P2_ID as a param.

  • AndyH
    AndyH Member Posts: 749 Bronze Trophy

    Is there a simpler way to show multiple pieces of data from different tables into read-only / display regions, without going to the custom HTML type display?

    I'm probably misunderstanding your query, but...

    You can have static region(s) where the page items are populated without the use of forms e.g. by using the default property of the item. However, it's probably easier to have a pre-region process to populate them e.g.

    select a,b,c into :P10_A, :P10_B, :P10_C from my_table where id = :P10_ID;
    select a,b,c into :P10_A2, :P10_B2, :P10_C2 from my_other_table where id = :P10_ID;
    


  • InoL
    InoL Member Posts: 9,347 Gold Crown
    edited Jul 29, 2021 8:35PM

    If you have multiple regions you want to query, you indeed need to alias the columns if they have the same column name (like ID). So far you're good.

    What you have to do in your calling URL is pass both parameters. E.g. if you are calling the form page from a IR, create the link to the form page with both ID columns, like this:

    ID2 is the alias for column ID in the 2nd table on the form page.

    Still, your data model seems a bit strange to me if you need something like this. Are there 1:1 relationships between your tables?

  • MrE-Oracle
    MrE-Oracle Member Posts: 12 Employee

    I'm not sure what is so strange about my data model or anything: all I want is have separate regions that call data from different tables that use the same key. Pretty standard stuff.

    Let's say for example I have Employee ID and a table with manager info, and another with the employee salary info. I want to show a region with the manager info, and a region with the salary info. How is that weird?

    Passing the ID multiple times sounds like a hack.

    Pre-creating multiple Page Items and selecting into them defeats the purpose of using a form that will create and populate these automatically.

    The problem, once again, is that I need to initialize the form TWICE to make the form init work as soon as I have more than 1 form.

    This just seems like a bug to me.

  • InoL
    InoL Member Posts: 9,347 Gold Crown

     a table with manager info, and another with the employee salary info. 

    Two tables, two different primary keys. That is how a relational model works.

    Even though you created emp_id in both tables as primary key, it doesn't mean it is the same key. Logically: yes, but technically: no.

    Pretty standard stuff

    Not really, in my opinion. You seem to have a 1:1 relationship between two tables, which is unusual in a relational model. A relational model is usually based on 1:N relationships, for which APEX can create master-detail forms,