<f:view> beforePhase method called twice when page loads - oracle-adf

I am trying to capture url parameters when page is loaded. I am using the beforePhase attribute inside the tag to call the backing bean method which handles the PhaseEvent. I am able to read the parameters but there seems to be some problem. The backing bean method is executed twice. First time I am getting all the url paramters but second time I am getting null.
This is the output in the console I get (The line "BeforePhase ONLOAD" is my SOP statement inside the method. As you can see the SOP is printed twice (below is the console output) -
* <_checkTimestamp> Apache Trinidad is running with time-stamp checking enabled. This should not be used in a production environment. See the org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION property in WEB-INF/web.xml
beforePhase ONLOAD
<_isBeanValidationAvailable> A Bean Validation provider is not present, therefore bean validation is disabled
beforePhase ONLOAD***
I have to use these url parameters to bind it to the view object and retrieve the data for the page. But if the method is called twice like it has been called here then the second will cause some database error or ultimately i will not see any records on screen.
Is there a way to handle this ?
I actually followed the Approach 1 example seen on this page - http://jneelmani.blogspot.com/2013/01/adf-how-to-call-method-on-page-load.html. In this example, he shows how to avoid beforePhase being called multiple times, I have done that but still the method is called twice.
Any suggestions here will be helpful.
Thanks.

Of course you know ADF supports a mechanism already for bookmarkable pages & URL parameters?
http://myadfnotebook.blogspot.pt/2010/11/bookmarking-with-adf.html

Related

Angular seems to fire on its own

I have a $http.put function that updates my database, this happens on a button click. After I update the database once, and stay on the page, with no interaction at all the update function gets called and will update the database with the last information that was inputted.
I've triple checked my code, there is only one occurrence of my update function being called. And the $http.put is inside $scope.update that is an anonymous function that calls the $http.put.
If I update information and then leave the page, and then come back the function does not fire on it's own.
Here is my Github for the project. I will pull out any specific code that you want to see, but I'm not sure what to show because there are 4 files involved. Those files are
(client/scripts/app.js)
(routes/products.js)
(public/views/routes/adminIndex.html)
(public/views/routes/modProduct.html)
Code is Here
Add a console.trace() just before the $http call to see what is calling it.
You can also use the developper console of your browser and add a breakpoint that will stop the code execution and let you inspect everything (stack trace, current context, etc). Chrome is particularly good at that.

Oracle ADF: Refresh Form data

I am developing a web app using Oracle ADF. I have a bounded task flow. In that I have a search page like below.
I have created the above two forms using view object data controls.
Searching is performing well. But my problem is when I go some where else in my application using menus provided left side and come back to the search page , the page is not getting refreshed. I am getting a search page that contains old search results. At this point of time if I am trying to make any changes am getting some error called "Another user with this id already modifed data ....". After this error my app is not running. Means what ever am trying to do its showing the same error.
So I need to make this: "When ever the user come to this form, He should get fresh form. It should not contain old search results.
Please help me. How do I achieve this.
Thank you.
There are 2 ways of doing it:
1) Set your task flow as ISOLATED, from Task Flow Overview tab -> Behaviour -> Share Data Control with calling task flow -> unchecked (or isolated, if you are using JDev 12c)
This will ensure you always start FRESH when accessing the page, but it will potentially create a performance overhead because entire View Object cache will be recreated (requeried) on page load. Nevertheless, it is the quickest solution.
2) You may create a default Method Call Activity in your task flow from where you may call a AM's custom method that resets the view criteria. The method will be placed on application module's implementation class and it may look like this:
public void initTaskFlow() {
this.getViewObject1().executeEmptyRowSet();
}
This will clean the result data. If you want to reset the querying parameters as well, you can use this example:
http://www.jobinesh.com/2011/04/programmatically-resetting-and-search.html
When you made any changes to any viewObject then excute this viewObject to match entity state and viewState , i think excuting viewObject will solve your issue
Ashish

cakephp where do I call a global function which each page needs

I'm using CakePHP (2.2 I think) and am struggling to know where to put a function. It's a function which is called on each page load. The basic logic is
Page is requested
loads page template
loads included header
to check if a cookie has been set.
If cookie is set, use values in that
if cookie hasn't been set, load a value from the database and save in the cookie
save cookie values in a config value to use across the page
continue loading page
Basically the function is to set the config values. I have tried to create a helper which worked nicely as I called it on the header view - but as soon as I try to access the cookie helper it didn't work.
I moved the code in to the app controller and called it on the beforefilter() function, but it seems to get called several times on the one page (even though this does actually all work ok).
So - where would I place a function to do this to get called before ANY html is drawn to the screen and is called only once?
Many thanks,
Matt.
beforeFilter of your AppController.php is the right place. beforeRender should also work, as #zynder mentioned.
beforeFilter should definitely only be called once per request by Cake. If it's working in beforeFilter, but it's being called more than once, you've probably done something wrong, and you should look into that. Or, maybe you could be mistaken in thinking it's executed more than once per request.
Why do you think beforeFilter is being called more than once?

How to get latest object in PageFactory without/with doing InitElements?

I am using PageFactory model in selenium framework (WebDriver, Java).
Test: Create an entity in application and wait until it will get complete ( To verify state of entity (completed/in-process) , I have to verify status image in-front of created entity).
Issues/Queries:
** How should I wait for specific status should get change from In-process to Complete? (As whole page is not getting refresh after completion, only that image is getting refresh – AJAX/JSON Call)
***How should I get latest page objects using PageFactory? I have tried using PageFactory.InitElements(driver, classname.class), but it’s not working.
**Is any way, we can refresh only PageFactory Cache? Like SilkTest having ‘BrowserPage.FlushCache()’?
The WebElements defined with the #FindBy annotation are effectively proxies. Every time you perform an action with the WebElement it uses the locator in the #FindBy annotation to find that element on the page again.
PageFactory.InitElements(driver, classname.class) just sets up these proxies, it doesn't actually find the elements so you don't need to keep calling it again and again.
You can cache individual WebElements by using the #CacheLookup annotation, if you use this the WebElement will be lazily evaluated the first time that you utilise it, but from that point onwards it will not be looked up again (which means you could start getting StaleElementExceptions if the element changes).
The latest information is kept in the Selenium Wiki:
http://code.google.com/p/selenium/wiki/PageFactory

Make an asynchronous call from Oracle ADF

I have an af:outputText on my page.
Its value takes a long time to generate, so I don't want to generate when initially creating the page.
Instead, I'd like the page to make an asynchronous call back to the server once loaded, the return value will then populate the outputText.
What is the best way of achieving this in ADF?
... or you use an af:poll component that checks the available status of the queried data. If the data is available, you disable the poll (ensure you PPR the af:poll component then)
Frank
Here is a hare-brained idea that might work:
set your outputText's rendered property to false; This will cause its value expression not be evaluated while your page is being loaded.
On load of the page, fire a javascript AdfCustomEvent towards a server listener which will then toggle the rendered state and PPR the outputText.
A more complex but probably cleaner approach would be to look into ADS to lazy load the value somehow.
Active Data Service (ADS) is a good fit for this. See http://docs.oracle.com/cd/E15523_01/web.1111/b31974/adv_ads.htm
Also Lucas Jellema has a great example of using ADS at http://technology.amis.nl/2011/10/19/adf-faces-handle-task-in-background-process-and-show-real-time-progress-indicator-for-asynchronous-job-using-server-push-in-adf/
Use af:poll and set the partial trigger of af:OutputText to af:poll so that the OutputText will automatically get refreshed on the first poll.In the poll listener set the poll interval to -1 (disable it)

Resources