Set Page Item Value on Page load oracle apex - oracle

I am trying to set a value of a page element on page load in the beginning.
The value is dependent on another element that has already been retrieved from the DB and is already set at the beginning.
To set the id I created a function and I call this function for the dynamic action on page load like this:
declare
id number;
begin
id:= set_ID(V('P1_page_item'));
apex_util.set_session_state('P17_ID',id);
end;
However the value for the page item is not being set.
Do you have any suggestions how an page item value can be set on page load?

There are many ways to set the value of a page item on page load. You can use a page process, a computation, a default value for the page item or a source value for the page item. A dynamic action is a possibility as well, but I have never done that...
Personally I find a computation the cleanest way of setting a value to a page item. It is meant just for that - computing a value for an item. In your case, you could create a computation for item P17_ID of type expression with source set_ID(:P1_PAGE_ITEM)
Now the problem of the page item not being set is probably something else. Try to give as much information as possible about the page to give us clues as to why this is not being set correctly. Have you run the page in debug ? That should give you an idea of what is happening.
On a side note:
The function V should not be used in an application. It was created to allow referencing of apex item values outside of the context of an application, for example in a stored procedure or a view. Using the V function has performance issues and should be avoided if possible. In the application, just use the bind variable syntax (:P1_ITEM) to reference and set variable values.
How is P1_PAGE_ITEM being set ? As a best practice try to avoid referencing page items on other pages. P1_PAGE_ITEM should only be referenced and manipulated on page 1 and so on. Using branches or links you'd then set a corresponding item P17_PAGE_ITEM on page 17. This will save you a lot of debugging time later on. Also, if you clear cache on page 1, then the value of P1_PAGE_ITEM will be wiped out which could lead to unexpected behaviour if that page item exists on other pages.

I'd use
id := set_ID(:P1_PAGE_ITEM);
Also, did you set dynamic action to fire on initialization? I presume you should.

Related

UFT: Problem in extracting data from excel file and input in the application dynamically

I am facing issues in performing certain actions based on the value in the excel file cell data.
Actions like if value is "NORMAL" then click Container type = Normal (radio button)
Similarly the Unit Container Value
Following is my code:
I am getting this error while performing action .WebElement("Container_Type_Normal").Click
Your error is because you can't start a line with . unless your within a with - and i can't see a with in your function. (i also don't recommend using a with as the can cause needless confusion)
The .webelement object is a catch-all type of object that is the child of other web objects or .page. You need this to be a full and valid path to the object, by this i mean start with browser().page().
You have a couple of options:
You can either make this a full path to your object based on the object repository:
Browser("<<OR Browser name>>").Page("<<OR Page name>>").WebElement("<<Your webelement name>>".click
For this, look at your OR and insert your names.
Or, option 2, you can use descriptive programming:
Browser("CreationTime:=0").Page("index:=0").WebElement("text:=" & fieldValue,"index:=0").click
That will take the browser that was created first (Creation time 0), the only page it has and the first (index 0) web element that contains your text (text is field value).
I'm assuming that you only have one browser, and that the first element that contains the text you want is what you want to click. You may need to add more layers too this or
A good approach is to mirror what is OR or use the object spy to ensure these properties are correct.

Don't load table on first load Oracle ADF

Everytime my page comes up it executes the table query. I tried doing this,
https://blogs.oracle.com/shay/entry/preventing_queries_when_page_f
but it still happens. How can I fix this? I've tried setting the refresh condition to never, but then I can't get any data back. I'm using JDev 11g.
Thanks.
I can share how I did this in JDeveloper 12.1. I am not sure whether it works in 11g. Nor am I sure it's the best way to do it. But it worked for me.
The idea is to not prevent the initial query execution, but, rather, to make sure it happens quickly and returns no data. The approach is to set the initial query criteria in the View Instance of your Application Module.
This approach assumes you have at least one bind variable in your view object. If you do not, you will need to add one just for this.
Double click on the Application Module
Click on the "Overview" tab at the bottom
Click on the "Data Model" tab on the left, so that you are viewing the Data Model Components of your Application Module
In the "Data Model" tree on the right, click once on the View Object Usage ("MyObjectVO1", e.g.).
Click the "Edit..." in the upper-right corner of the Data Model tree.
Here, you can specify view criteria to be used initially for the page. So,
* Set an initial parameter that will (A) execute quickly and (B) return no data
Then, later, programatically reset the bind variables to correct values that will return data, when you are ready to let your query run.
The most simple way i know is to set up correctly "Refresh" attribute on iterator in the page definition.
To do that set refresh=ifNeeded, then set RefreshCondition with expression language, something like this: #{viewScope.yourBean.refresh}
public class YourBeanClass {
private boolean refresh = false;
public void someAction(ActionEvent actionEvent) {
//some custom logic to set refresh flag
refresh = true;
}
public boolean isRefresh() {
return refresh();
}
}
With this code you can simply manage the moment when you need to refresh your model.
While these solutions will work to prevent the query from executing, I would ask what is the use case that a user sees a table appear on a web page without doing a search first?
ADF is built to query automatically because normally a web page will have an af:query or af:quickquery component on the page to allow the user to enter a query. Once the query is executed, the results are returned and populate the table or form (depending on the page design). Including either of these search components on the page will prevent the page from executing the query until the search is executed. You can also execute a query on entry to the page using a taskflow and adding an Execute operation from the data control to the navigation into/prior to getting to the page.
Note that Shay's blog post is from 2009 and covers the use case of not using a search component and instead uses Execute with Params. Is this what you are using? Saying more about your use case would be helpful.

apex retrieve default item value

Is it possible to get default item value using plsql? I have a validation and in case it fails I want to reset item to its default value.
I tried using apex_util.set_session_state('P_ITEM_NAME', null) but that did not have any noticeable effect.
How can default item be retrieved or item itself be reset?
When creating a page process, there is a condition called "Inline validation errors displayed", maybe this will help? In this process you can reset items to null, then when page loads, item values will return to their default values.
UPD:
Create process:
Process Point: On Load Before header
Condition: Inline Validation Errors Displayed
Process source:
begin
for i in (
select t.ITEM_DEFAULT, t.item_name
from apex_application_page_items t
where t.application_id = :APP_ID
and t.page_id = :APP_PAGE_ID
) loop
apex_util.set_session_state(i.item_name, i.item_default);
end loop;
end;
This will return all page items to their default values.
This solution some ugly, but i don't know another solution for this problem.
:P_ITEM_NAME := null;
The difference here is the ":" infront of the item. Using it like this will give access to the item. Using apostrophes isn't needed I believe.
If this doesn't work with your version try without the ;.
So you can use:
:P_ITEM_NAME
To get the value.
I could not find any function that would return me default value using an item. However I could use default item setting to mimic this. Page processes do not run when page has validation errors, so I added conditional page process that performs the same checks as my validation and when these checks indicate that validation fails it just clears item state.
This is ugly as it requires checks to be duplicated and it seems that it is necessary to replicate almost same page controls through all pages where such reset mechanism is necessary.

joomla lost data in jos_session

$session = JFactory::getSession();
$session->set('domain_name', $domain_name, 'dominiForm');
then the table jos_session contains ...__dominiForm|a:2:{s:11:"domain_name";s:16:"safafasfsadfsfds";s:15:"tld_da_comprare";a:1:{i:0;s:3:".com";}}
I have checked that session life is 45mins in joomla control panel.
However without using set() or clear() it randomly(i think after a few minutes of pause) when i click "next" i end up with the database containing only this ...__dominiForm|a:0:{}
This happends both with 1.5 and 2.5.
I believe your problem exists with parts of the code that you haven't shown. It sounds like the $session->set() is getting called during a point when you aren't expecting it to be called, and it is empty at that point so it is overwriting the stored value with an empty value. Post more of your code and I may be able to point out where the issue is.

Oracle Forms Builder - change to window in another form

We have two forms so far, and need to switch from window1 in from1 (which is login screen) to windowX in formX using button (trigger code below):
begin
show_window('windowX');
go_block('some_block_in_formX');
end;
This gives error FRM-41052: Cannot find Window: invalid ID
So question is, should I add formX into show_window parameter in certain way or is there another approach? Thank you.
Please note, that forms are in different files.
that forms are in different files.
If the forms are different files, you need to call the other form using open form/call form/newform - whatever suits your needs.
show_window/go_block sequence can be used only when you're moving to different windows/blocks of the same form - and the error message
error FRM-41052: Cannot find Window: invalid ID
is complaining that it can't go to that Window because it's in a different form.
Each form effectively has a private namespace for all its windows, blocks, items, etc - and your code always runs within the context of a single form.
To solve this, you'll need a form parameter, plus some code in the other form, e.g.:
in formX, add a parameter ACTION
in form1, pass the value 'XYZ' to ACTION
in formX, in the WHEN-NEW-FORM-INSTANCE trigger, check if :PARAMETER.ACTION = 'XYZ', and if so, do your show_window and go_block. Copy the same code to your WHEN-WINDOW-ACTIVATED trigger.
Of course, you'll need to think about the name of the parameter (e.g. ACTION) and value ('XYZ') that will make sense to people maintaining your forms in the future.

Resources