I have two faceted search pages in my oracle apex application. I want to create a dynamic action such that if I select a facet in one page it should be automatically selected in other page as well. How do I accomplish this?
1 Answers
Here is one possible solution by using a DA alongside with browser localStorage.
Let me warn you that this solution doesn't work on multiple choice searches (e.g. checkboxes etc.). Also you should be sure that your browser support local storage.
Solution
First create two pages lets call it SECOND and THIRD (Home is by default the first page). Both pages has a Faceted Search with a Facet called PX_DEPTNO which filters out the records by departments.
On the SECOND page create two DAs with the following specs:
First DA
- Name: Set data
- Event: Page Load
- Create one True action the type should be: Execute JavaScript code
- Code:
var myStorage; if ( apex.storage.hasLocalStorageSupport() ) { myStorage = apex.storage.getScopedLocalStorage({ prefix: "FSearch" }); apex.item("P2_DEPTNO").setValue(myStorage.getItem("DEPTNO")); }
Second DA
- Name: Store data
- Event: Page Unload
- Create one True action the type should be: Execute JavaScript code
- Code:
var myStorage; if ( apex.storage.hasLocalStorageSupport() ) { myStorage = apex.storage.getScopedLocalStorage({ prefix: "FSearch" }); myStorage.setItem( "DEPTNO", $v("P2_DEPTNO") ); }
Now on the THIRD page create two similar DAs:
First DA
- Name: Set data
- Event: Page Load
- Create one True action the type should be: Execute JavaScript code
- Code:
var myStorage; if ( apex.storage.hasLocalStorageSupport() ) { myStorage = apex.storage.getScopedLocalStorage({ prefix: "FSearch" }); apex.item("P3_DEPTNO").setValue(myStorage.getItem("DEPTNO")); }
Second DA
- Name: Store data
- Event: Page Unload
- Create one True action the type should be: Execute JavaScript code
- Code:
var myStorage; if ( apex.storage.hasLocalStorageSupport() ) { myStorage = apex.storage.getScopedLocalStorage({ prefix: "FSearch" }); myStorage.setItem( "DEPTNO", $v("P3_DEPTNO") ); }
This is an example and you can choose also another storing method (which could be a better solution) like Cookies or Session storage, but it is up to you.
Also consider to create a JS library since there is a lot of duplicate code.