المكتبة التقنية ←

إنشاء ملخص طلب قابل للتحديث باستخدام Dynamic Content في Oracle APEX

English version

A purchase-order summary can need a layout that follows the business process. My original LinkedIn post used Oracle APEX Dynamic Content to combine a selected order's details with custom HTML. This walkthrough starts with a small summary showing customer, total, and status.

Return HTML as a CLOB

On a development page, add a Select List named P10_ORDER_ID with values 1001 and 1002. Create a Dynamic Content region, set its Static ID to order_summary, and use a PL/SQL function body returning a CLOB as its source. Match the item name to your actual page if you use another page number.

The region returns its constructed HTML to APEX. Oracle describes the CLOB source and CSS-class approach in its Dynamic Content guide. Dynamic Content

The example query uses two synthetic rows from DUAL. Paste this function body into the region source.

declare
    l_customer varchar2(200);
    l_total    number;
    l_status   varchar2(30);
begin
    select customer_name, order_total, order_status
      into l_customer, l_total, l_status
      from (
          select '1001' as order_id,
                 'Sample <Customer>' as customer_name,
                 125.50 as order_total,
                 'Ready' as order_status
            from dual
          union all
          select '1002', 'Second Customer', 78, 'In review'
            from dual
      )
     where order_id = :P10_ORDER_ID;

    return to_clob(
        '<article class="order-summary"><h3>Order summary</h3><dl>'
    )
        || '<dt>Customer</dt><dd>'
        || apex_escape.html(l_customer) || '</dd>'
        || '<dt>Total</dt><dd>'
        || apex_escape.html(to_char(
               l_total, 'FM999990D00',
               'NLS_NUMERIC_CHARACTERS=''.,'''
           )) || '</dd>'
        || '<dt>Status</dt><dd>'
        || apex_escape.html(l_status) || '</dd>'
        || '</dl></article>';
exception
    when no_data_found then
        return to_clob('<p>Select an available demo order.</p>');
end;

The customer name deliberately contains angle brackets so you can check that they appear as text. Values inserted into HTML text nodes pass through APEX_ESCAPE.HTML. Keep attribute and URL handling specific to their own output contexts when extending the markup. HTML escaping

Send the selected value when refreshing

Add P10_ORDER_ID to the region's Page Items to Submit property, without a colon. Create a Dynamic Action on the item's Change event, with a Refresh action targeting the summary region. This sends the current selection to the server during the refresh request. Items to submit

Style and check the summary

Place these rules in the page's Inline CSS or the application's stylesheet.

#order_summary .order-summary {
  padding: 1rem;
  border: 1px solid currentColor;
  border-radius: 0.75rem;
}
#order_summary .order-summary dl {
  display: grid;
  grid-template-columns: minmax(6rem, 1fr) minmax(0, 2fr);
  gap: 0.5rem 1rem;
}
#order_summary .order-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

Switch between both demo orders and verify that the customer, total, and status change together. Check the empty-selection message, narrow screens, keyboard operation, and an Arabic page direction. Keep the status readable as text.

When replacing the synthetic rows with application data, apply row access rules in the query and authorize access to the region. Use translated text messages for the headings and labels in a multilingual application. Review the rendered HTML after each change to the data or layout.

Original LinkedIn post

النسخة العربية

ملخص طلب الشراء قد يحتاج تصميمًا يناسب إجراءات العمل. بوستي الأصلي على LinkedIn استخدم Dynamic Content في Oracle APEX لدمج بيانات الطلب المختار مع HTML مخصص. الشرح التالي يبدأ بملخص صغير يعرض العميل والإجمالي والحالة.

أرجع HTML في قيمة CLOB

في صفحة تطوير، أضف Select List باسم P10_ORDER_ID بقيمتي 1001 و1002. أنشئ منطقة Dynamic Content وحدّد Static ID بقيمة order_summary، واستخدم PL/SQL Function Body returning a CLOB كمصدر. لو رقم صفحتك مختلف، طابق اسم العنصر مع الصفحة الفعلية.

المنطقة ترجع HTML الذي كوّنته إلى APEX. يوضح توثيق Oracle مصدر CLOB واستخدام CSS Classes مع المنطقة. Dynamic Content

الاستعلام في المثال يستخدم صفّين افتراضيين من DUAL. ضع جسم الدالة التالي في مصدر المنطقة.

declare
    l_customer varchar2(200);
    l_total    number;
    l_status   varchar2(30);
begin
    select customer_name, order_total, order_status
      into l_customer, l_total, l_status
      from (
          select '1001' as order_id,
                 'Sample <Customer>' as customer_name,
                 125.50 as order_total,
                 'Ready' as order_status
            from dual
          union all
          select '1002', 'Second Customer', 78, 'In review'
            from dual
      )
     where order_id = :P10_ORDER_ID;

    return to_clob(
        '<article class="order-summary"><h3>Order summary</h3><dl>'
    )
        || '<dt>Customer</dt><dd>'
        || apex_escape.html(l_customer) || '</dd>'
        || '<dt>Total</dt><dd>'
        || apex_escape.html(to_char(
               l_total, 'FM999990D00',
               'NLS_NUMERIC_CHARACTERS=''.,'''
           )) || '</dd>'
        || '<dt>Status</dt><dd>'
        || apex_escape.html(l_status) || '</dd>'
        || '</dl></article>';
exception
    when no_data_found then
        return to_clob('<p>Select an available demo order.</p>');
end;

اسم العميل يحتوي عمدًا على علامات زاوية لتتأكد أنها تظهر كنص. القيم التي تدخل في مواضع النص داخل HTML تمر عبر APEX_ESCAPE.HTML. عند توسيع التصميم، عالج خصائص HTML والروابط بما يناسب سياق كل منها. حماية النصوص داخل HTML

أرسل القيمة المختارة عند التحديث

أضف P10_ORDER_ID إلى خاصية Page Items to Submit في المنطقة، بدون نقطتين قبل الاسم. أنشئ Dynamic Action على حدث Change للعنصر، وأضف إجراء Refresh يستهدف منطقة الملخص. الإعداد ده يرسل الاختيار الحالي إلى السيرفر أثناء طلب التحديث. العناصر المطلوب إرسالها

نسّق الملخص واختبره

ضع القواعد التالية في Inline CSS للصفحة أو في ملف CSS الخاص بالتطبيق.

#order_summary .order-summary {
  padding: 1rem;
  border: 1px solid currentColor;
  border-radius: 0.75rem;
}
#order_summary .order-summary dl {
  display: grid;
  grid-template-columns: minmax(6rem, 1fr) minmax(0, 2fr);
  gap: 0.5rem 1rem;
}
#order_summary .order-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

بدّل بين الطلبين وتأكد أن العميل والإجمالي والحالة يتغيروا معًا. راجع رسالة الاختيار الفارغ، والشاشات الصغيرة، واستخدام الكيبورد، واتجاه الصفحة العربية. احتفظ بالحالة مكتوبة كنص واضح.

عند استبدال الصفوف الافتراضية ببيانات التطبيق، طبّق قواعد الوصول للصفوف داخل الاستعلام وصلاحية الوصول للمنطقة. استخدم Text Messages مترجمة للعناوين والتسميات في التطبيق متعدد اللغات. راجع HTML الناتج بعد كل تغيير في البيانات أو التصميم.

البوست الأصلي على LinkedIn