Forum Stats

  • 3,782,429 Users
  • 2,254,644 Discussions
  • 7,880,078 Comments

Discussions

How to make reusable components in Apex?

DannyS-Oracle
DannyS-Oracle Member Posts: 165
edited Jan 25, 2018 11:54AM in APEX Discussions

Hi everyone,

I have been working with Apex for >1 year and loving how it simplifies app development in my small team. However I have not found satisfying solutions for some issue regarding reusability. I will really appreciate it if anyone can help me on tackling these pain points:

  1. Creating reusable page layout - most of the time I have multiple pages that shares the same regions, items, and logic. For example, I have a region which has been customized to have hidden heading, containing dropdown items, which are pulling its value from a shared component. This customized region and its content will be used in multiple pages. Every time I want to change an item / UI of the region, I will need to re-visit these pages one by one and updating them - this is really time consuming. I have seen people asking about this in another thread: , but it did not get results.
  2. Making pages detecting changes on the backend table - this is a frequent problem on my form and report pages. Let's say I decided to rename a table column, I will have to check one by one my Apex pages to find if there are any page item or report affected by this change. Is there a better way to detect these affected pages in one go?

In addition, does anyone know if there is sample app or website that talks about the best practices of Apex development? Thank you in advance!

P.S. I am using Apex v5.1

DannyS-Oracle

Best Answer

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,345 Red Diamond
    edited Jan 24, 2018 8:56PM Accepted Answer
    DannyS-Oracle wrote:Hi fac586, thanks for mentioning all possible solutions, I learned a lot from them.Let's say I have Page 1-10, which are intended to be metric pages (showing pie, bar charts). They all use the same page template, and they have a static region at page body which contains some select list items (filtering the chart based on time range, name of employee, and so on). If there is an update on this static region or its content (changing the text inside the region, changing the source of select list items), I want these changes to be applied to all Pages 1-10.

    That's a common use case for global page components. Set the Source Used property on the global page items to Only when current value in session state is null so they will retain their values in session state across page requests.

    Based on your suggested options, I think Global Page can be useful. But from my understanding, we can only have one Global Page per application? Is it possible to have >1 Global Page? And is it a good practice to fill my Global Page with many components (one region intended for Page 1 to 10, another region intended to be used by Page 22-27, and so on)?

    It is only possible to have one global page for each user interface type defined for the application (i.e. one for desktop pages and one for mobile). In practice this means one per application as the mobile UI is being deprecated.

    There are no issues with creating multiple global page components that will be included in pages according to defined conditions and/or security policies implemented in authorization schemes.

    Another example would be, I want to make sure all pages in my application to include a Breadcrumb, except the modal dialog pages. In my Global Page, do I have to manually specify "Current Page included in the comma delimited values" each time I added / deleted a page?

    Using the declarative, predefined condition types whenever possible is recommended for performance reasons. A Page is in Page Group condition would be useful but sadly doesn't exist. However it's possible to automate such rules using a [No] Rows returned condition with a query that uses page group or template information from the APEX_APPLICATION_PAGES view to exclude the breadcrumb region from login and modal pages. The application metadata exposed in the APEX views opens up all kinds of interesting possibilities.

    DannyS-Oracle

Answers

  • jariola
    jariola Member Posts: 10,542 Silver Crown
    edited Jan 24, 2018 2:37PM
    DannyS-Oracle wrote:Making pages detecting changes on the backend table - this is a frequent problem on my form and report pages. Let's say I decided to rename a table column, I will have to check one by one my Apex pages to find if there are any page item or report affected by this change. Is there a better way to detect these affected pages in one go?

    There is APEX views. Check for start e.g.

    APEX_APPLICATION_PAGE_DB_ITEMS

    APEX_APPLICATION_PAGE_RPT_COLS

    Also one way is change column name and run Advisor and Database Object Dependencies Report.

    Those shows most of affected pages and problems.

    DannyS-OracleDannyS-Oracle
  • fac586
    fac586 Senior Technical Architect Member Posts: 20,345 Red Diamond
    edited Jan 24, 2018 2:40PM
    DannyS-Oracle wrote:2. Making pages detecting changes on the backend table - this is a frequent problem on my form and report pages. Let's say I decided to rename a table column, I will have to check one by one my Apex pages to find if there are any page item or report affected by this change. Is there a better way to detect these affected pages in one go?

    The Database Object Dependencies Report utility is likely to prove useful. Additionally you can create custom reports specifically for your needs in this area using the APEX metadata views.

    DannyS-OracleDannyS-Oracle
  • fac586
    fac586 Senior Technical Architect Member Posts: 20,345 Red Diamond
    edited Jan 24, 2018 3:16PM
    DannyS-Oracle wrote:I have been working with Apex for >1 year and loving how it simplifies app development in my small team. However I have not found satisfying solutions for some issue regarding reusability. I will really appreciate it if anyone can help me on tackling these pain points:Creating reusable page layout - most of the time I have multiple pages that shares the same regions, items, and logic. For example, I have a region which has been customized to have hidden heading, containing dropdown items, which are pulling its value from a shared component. This customized region and its content will be used in multiple pages. Every time I want to change an item / UI of the region, I will need to re-visit these pages one by one and updating them - this is really time consuming. I have seen people asking about this in another thread: Reuse Regions as a Component like Packages? , but it did not get results.

    The main features APEX provides to promote component reuse are:

    It's not clear from the limited information posted which (if any) of these fit your requirements. More detail on the components you want to create would be helpful.

    Another option is simply to create pages or applications containing skeleton definitions for frequently used components, then copy and complete these as required. Earlier versions of APEX formalised this with support for Template Applications, but this useful feature mysteriously disappeared without fanfare in APEX 5.0.

    DannyS-OracleDannyS-Oracle
  • DannyS-Oracle
    DannyS-Oracle Member Posts: 165
    edited Jan 24, 2018 7:53PM

    Hi @fac586, thanks for mentioning all possible solutions, I learned a lot from them.

    Let's say I have Page 1-10, which are intended to be metric pages (showing pie, bar charts). They all use the same page template, and they have a static region at page body which contains some select list items (filtering the chart based on time range, name of employee, and so on). If there is an update on this static region or its content (changing the text inside the region, changing the source of select list items), I want these changes to be applied to all Pages 1-10.

    Based on your suggested options, I think Global Page can be useful. But from my understanding, we can only have one Global Page per application? Is it possible to have >1 Global Page? And is it a good practice to fill my Global Page with many components (one region intended for Page 1 to 10, another region intended to be used by Page 22-27, and so on)?

    Another example would be, I want to make sure all pages in my application to include a Breadcrumb, except the modal dialog pages. In my Global Page, do I have to manually specify "Current Page included in the comma delimited values" each time I added / deleted a page?

  • fac586
    fac586 Senior Technical Architect Member Posts: 20,345 Red Diamond
    edited Jan 24, 2018 8:56PM Accepted Answer
    DannyS-Oracle wrote:Hi fac586, thanks for mentioning all possible solutions, I learned a lot from them.Let's say I have Page 1-10, which are intended to be metric pages (showing pie, bar charts). They all use the same page template, and they have a static region at page body which contains some select list items (filtering the chart based on time range, name of employee, and so on). If there is an update on this static region or its content (changing the text inside the region, changing the source of select list items), I want these changes to be applied to all Pages 1-10.

    That's a common use case for global page components. Set the Source Used property on the global page items to Only when current value in session state is null so they will retain their values in session state across page requests.

    Based on your suggested options, I think Global Page can be useful. But from my understanding, we can only have one Global Page per application? Is it possible to have >1 Global Page? And is it a good practice to fill my Global Page with many components (one region intended for Page 1 to 10, another region intended to be used by Page 22-27, and so on)?

    It is only possible to have one global page for each user interface type defined for the application (i.e. one for desktop pages and one for mobile). In practice this means one per application as the mobile UI is being deprecated.

    There are no issues with creating multiple global page components that will be included in pages according to defined conditions and/or security policies implemented in authorization schemes.

    Another example would be, I want to make sure all pages in my application to include a Breadcrumb, except the modal dialog pages. In my Global Page, do I have to manually specify "Current Page included in the comma delimited values" each time I added / deleted a page?

    Using the declarative, predefined condition types whenever possible is recommended for performance reasons. A Page is in Page Group condition would be useful but sadly doesn't exist. However it's possible to automate such rules using a [No] Rows returned condition with a query that uses page group or template information from the APEX_APPLICATION_PAGES view to exclude the breadcrumb region from login and modal pages. The application metadata exposed in the APEX views opens up all kinds of interesting possibilities.

    DannyS-Oracle
This discussion has been closed.