Wizard
Wizard

Reputation: 11295

Oracle Forms list does not display values

I want to make list which will display values, like text item but in list.

My code:

DECLARE
      rg_dept     RecordGroup;
   
      rg_dname    VARCHAR2(4) := 'Name';
     
      dlist_ID    Item := Find_Item('PROJESCT.LIST_ID');
    
      nDummy      NUMBER;
BEGIN
      rg_dept := Find_Group(rg_dname);
   
     
      -- Delete any existing Group first
      IF NOT Id_Null(rg_dept) THEN
            Delete_Group(rg_dept);
      END IF;
  
      -- Now create a Record Group using a SQL query
      -- Your Query must have a Label and a Value (two Columns)
      -- and the data types must match your item type   
      rg_dept := Create_Group_From_Query(rg_dname,'SELECT department_name, to_char(department_id) FROM departments');
    
 
      --Clear the existing List
      Clear_List(dlist_ID);
   
 
      -- Populate the Record Group
      nDummy := Populate_Group(rg_dept);
      
 
      -- Populate the List Item
      Populate_List(dlist_ID ,rg_dept);
     
END;

If I make list item and add this code, form will display nothing; if I remove list, all is ok.

P.S. Trigger: when-list-item-change

Upvotes: 1

Views: 6110

Answers (2)

Peter Å
Peter Å

Reputation: 1319

I should recommend you to populate your lists from e.g. When-new-Form-Instance. As usual you will get a good idea what you need to do from Forms help (menu 'Help/Online Help'). This is a procedure I have made to simple populate list only by specifying the name of the list item and the select statement to populate the lsit item with.

PROCEDURE populate_list_item (
  p_item_name   VARCHAR2
, p_select  VARCHAR2
) IS
    l_rg_id         RECORDGROUP;
    l_list_id       ITEM;
    l_err_num       PLS_INTEGER;

    FUNCTION create_temp_group (
      p_select      VARCHAR2
    ) RETURN RECORDGROUP IS
        l_rg_id     RECORDGROUP;
        l_group_name    VARCHAR2(30) := 'TMP$RG';
    BEGIN
        l_rg_id := FIND_GROUP(l_group_name);

        --Make sure that record group don't alreay exist
        IF NOT ID_NULL(l_rg_id) THEN
           DELETE_GROUP(l_rg_id);
        END IF;

        --Populate the temporary record group
        l_rg_id := CREATE_GROUP_FROM_QUERY(l_group_name, p_select);

        RETURN l_rg_id;
    END create_temp_group;

BEGIN
    l_rg_id := create_temp_group(p_select);

    l_err_num := Populate_Group(l_rg_id);

    --Allow for no data found in the selection query
    IF l_err_num NOT IN (0, 1403) THEN
        RAISE Form_Trigger_Failure; 
    END IF;

    l_list_id := Find_Item(p_item_name);
    IF ID_NULL(l_list_id) THEN
        RAISE Form_Trigger_Failure; 
    END IF;

    Populate_List(l_list_id, l_rg_id);

    Delete_Group(l_rg_id);
END populate_list_item;

The When-New-Form-Instance is a form level trigger and should be under the form (instead of block or item):

Adding of When-New-Form-Instance

Upvotes: 2

Art
Art

Reputation: 199

The best thing to do is to build all your record groups at design time. It does not slow down the performance unless you have some huge, already slow form. Then populate your list items at run time. Always Copy/paste the code from Forms help.

--Oracle Forms Example: Create a record group from a query, and populate it.

DECLARE 
  rg_name VARCHAR2(40) := 'Salary_Range'; 
  rg_id RecordGroup; 
  errcode NUMBER; 
BEGIN 
/* 
** Make sure group doesn't already exist 
*/ 
 rg_id := Find_Group( rg_name ); 
/* 
** If it does not exist, create it and add the two 
** necessary columns to it. 
*/ 
IF Id_Null(rg_id) THEN 
 rg_id := Create_Group_From_Query( rg_name, 
  'SELECT SAL-MOD(SAL,1000) BASE_SAL_RANGE,' 
   ||'COUNT(EMPNO) EMPS_IN_RANGE ' 
   ||'FROM EMP ' 
   ||'GROUP BY SAL-MOD(SAL,1000) ' 
   ||'ORDER BY 1'); 
END IF; 
/* 
** Populate the record group 
*/ 
  errcode := Populate_Group( rg_id ); 
END; 

Upvotes: 2

Related Questions