Forum Stats

  • 3,874,157 Users
  • 2,266,675 Discussions
  • 7,911,745 Comments

Discussions

Refresh shuttle using dynamic action without clearing the previous selected values

S-Max
S-Max Member Posts: 217 Bronze Badge
edited Jan 20, 2016 9:40AM in APEX Discussions

Hello all,

I have a page with 2 items (textfield and shuttle-item) and one button: https://apex.oracle.com/pls/otn/f?p=46687:1

Username: guest

Password: gast

With the textfield I would like to filter the shuttle item. This works fine, but it clears the previously selected shuttle values.

For exaple:

  1. Enter in the text-element "mi" and click on the button "Search"
  2. Select "MILLER" in the left field of the shuttle item and move it to the right item of the shuttle
  3. Now enter in the text-element "ad" and click on the button "Search"
  4. The shuttle item will be refreshed, but the right field of the shuttle item will be cleared.

Is it possible to realize this requirement using APEX and dynamic actions so, that after the shuttle-refresh the previously selected values are not deleted?


Best regards

Tagged:

Answers

  • InoL
    InoL Member Posts: 10,196 Blue Diamond
    edited Jan 19, 2016 11:05AM

    If you change items in the shuttle and want to save the selected items, you should commit the changes in the database.

    But it looks like you have other problems on your page, as sometimes it works, sometimes it doesn't, sometimes you see the employee number etc. What is the source and the LOV of your shuttle? What does your Search button do?

  • S-Max
    S-Max Member Posts: 217 Bronze Badge
    edited Jan 20, 2016 7:10AM

    Hi,

    thank you for the answer!

    I have already changed the standard behaviour of shuttle item with some javascript and I hope, this works correctly. Except of pressing the "enter" key in the filter-item.

    I don't know why after the pressing of the "enter" key in that item the page will be reloaded. I have set the option "Submit when Enter pressed" of the Filter-Item "P1_SHUTTLE_FILTER_ITEM" to NO...

    Strange problem:

    Sometimes while filtering using the button "Search", sumetimes while pressing the enter key in the filter item, or manually refresh the page with F5 the already selected employees will no be shown in the right field of the shuttle, but IN THE LEFT FIELD!!!

    VERY STRANGE...

    pastedImage_178.png

    And much more: it looks like the f...... internet explorer 9 to 11 shows the selected employees always in the left shuttle field!

    I have not test it with Microsoft Edge.

    Here is the page content:

    Page Attributes:

    1. Function and global variable decöaration:

    var p_array = "";

    var pShuttle2 = "P1_SHUTTLE_ITEM_SELECTED_VAL";

    var shuttleItemRight;

    Page items:

    P1_SHUTTLE_FILTER_ITEM - Text Field

    P1_SHUTTLE_ITEM_SELECTED_VAL - Hidden

    P1_SHUTTLE_ITEM - Shuttle Item

                  LOV:

                        SELECT ENAME, htf.escape_sc(EMPNO) EMPNO

              FROM   EMP

              WHERE  lower(ENAME) LIKE '%'||lower(:P1_SHUTTLE_FILTER_ITEM)||'%'

              AND    instr(':'||:P1_SHUTTLE_ITEM_SELECTED_VAL||':', ':'||EMPNO||':') = 0

              ORDER BY ENAME

                  Display Extra Values: YES

    Buttons:

    P1_BUTTON_SEARCH with Action = "Defined by dynamic action"

    Dynamic Action "Set P1_SHUTTLE_ITEM_SELECTED_VAL":

    Event: change

    Selection Type: Items

    Items: P1_SHUTTLE_ITEM

    Condition: is not null

    True action "Execute PL/SQL Code": :P1_SHUTTLE_ITEM_SELECTED_VAL := :P1_SHUTTLE_ITEM;

    Page Items to submit: P1_SHUTTLE_ITEM_SELECTED_VAL,P1_SHUTTLE_ITEM

    Page Items to return: P1_SHUTTLE_ITEM_SELECTED_VAL

    Fire on Page Load: NO


    Dynamic Action "Refresh Shuttle on Button Search":

    Event: "Click"

    Selection Type: "Button"

    Button: "P1_BUTTON_SEARCH"

    Condition" no condition"

    1. True Action "Execute PL/SQL Code": NULL;

    Page Items to Submit: P1_SHUTTLE_FILTER_ITEM

    Page Items to Return: P1_SHUTTLE_FILTER_ITEM

    Fire on Page Load: NO

    2. True Action "Execute JavaScript Code" (stores the pre-changed element in the global javascript variable shuttleItemRight and in the shuttle selected values in the javascript array p_array):

    Fire on Page Load: YES

    shuttleItemRight = $x(pShuttle2);

    for (i = 0; i < $x(pShuttle2).length; i++)

    {

      if (p_array == '')

      {

        p_array = $x(pShuttle2)[i].value;

      }

      else

      {

        p_array = p_array + ':' + $x(pShuttle2)[i].value;

      }

    }

    3. True Action "Refresh Shuttle"

    Action: Refresh

    Selection Type: "Item(s)"

    Item(s): P1_SHUTTLE_ITEM

    Fire on Page Load: YES

    4. True Action "Execute JavaScript Code" (calls the on-demand app process populateRightShuttleItem and populates the right shuttle item with the selected employees from the javascript global variable shuttleItemRight):

    Fire on Page Load: YES

    var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=populateRightShuttleItem',0);

    get.addParam('x01', $v(shuttleItemRight));

    gReturn = get.get();

    resp = eval(gReturn);

    shuttleItemRight = $x("P1_SHUTTLE_ITEM_RIGHT");

    if(gReturn && shuttleItemRight)

    {

      for ( var i=0; i<resp.length; i++ )

        shuttleItemRight.options[i] = new Option(resp[i].data, resp[i].id);

    }

    get = null;

    resp = null;

    On-Demand Application Process "populateRightShuttleItem":

    DECLARE

      l_selected long := wwv_flow.g_x01;

      v_count    NUMBER := 0;

    BEGIN

      htp.prn('[');

      FOR i IN (SELECT EMPNO, ENAME

                FROM   EMP

                WHERE  instr(':'||l_selected||':', ':'||EMPNO||':') > 0

                ORDER BY ENAME) LOOP

        v_count := v_count + 1;

        htp.prn( case when v_count > 1 then ',' else null end ||

                 '{ id: ' || i.EMPNO ||

                 ', data: "' || i.ENAME || '"}' );

      END LOOP;

      htp.prn(']');

    EXCEPTION

      WHEN OTHERS THEN

        htp.p(SQLERRM);

    END;

    Best regards

  • InoL
    InoL Member Posts: 10,196 Blue Diamond
    edited Jan 20, 2016 9:18AM
    I have already changed the standard behaviour of shuttle item
    

    Why did you do that? What was not working for you using standard functionality?

  • S-Max
    S-Max Member Posts: 217 Bronze Badge
    edited Jan 20, 2016 9:23AM

    By default, after refreshing of shuttle item, the right element of shuttle item (the selected employees) will be cleared. I need to presave this values

  • InoL
    InoL Member Posts: 10,196 Blue Diamond
    edited Jan 20, 2016 9:40AM

    Absolutely, that's why I had this first remark:

    If you change items in the shuttle and want to save the selected items, you should commit the changes in the database.

    Here's an example:

    http://dgielis.blogspot.com/2015/01/using-shuttles-in-many-to-many.html

    This might not be your situation, but the many-to-many relation is the most common use for shuttles.

This discussion has been closed.