XPages: beforePageLoad runs more than once... Why? - java

We have this XPages application that has one master page (say M.xsp) and several sub-pages, all in separate iframes on the master page (loaded as A.xsp, B.xsp and C.xsp in separate tabs). The application runs fine, generally speaking. Each sub-page shouldn't interfere with the other pages, and as far as I know, it doesn't. Some page-dependent data is stored in viewScope variables, but for the most important parts we developed Managed Beans, with their data mostly in view-scope too.
Now, what we see is the following:
on page A, we do several clicks and some AJAX calls occur to fetch data from the server
we switch to page B, we do 3 AJAX requests for data to the server
we switch back to page A, we do one click to fetch some data again, and a beforePageLoad event occurs! Needless to say, the page is still loaded.
on the same page A, we do a new click to fetch different data, and beforePageLoad is triggered again!
viewScope is lost, my page-dependent bean is lost, very strange.
We checked, but changing the amount of memory dedicated to XPages didn't change anything.
XPages 9.0.1, browser-only.
Can someone please explain this behaviour: how come beforePageLoad is repeatedly executed? How can we prevent it?
Thanks!!

Twas indeed related to the max number of pages in memory. Every time an item in a list on page B was clicked, a sub-page (B1) was loaded in yet another iframe, using a URL with the item as parameter. Many clicks in the list forced many pages to load, causing all other pages disappear from memory. So when we moved back to page A and triggered some partial refresh there, it was as if the the page was new to the runtime environment.
I rewrote the sub-page B2 to stay in memory, and do a partial refresh itself when the list value changes. Quite a lot faster, and no unnecessary page drops.

Related

Should we write separate page-object for pop-up with a selection drop-down?

I am new to Page-Object model automation using selenium and java. I am using the Page Object model and have each page as a single class and the actions in that page as methods.
Should we write separate page-object for a simple pop-up which appears when submitting a form. This pop up is used to select service types and based on the selection correct form will be opened next. I have 'page objects' for the pages before and after this pop up. But for this one I just inserted a direct code to select an option and click next button. Should I create a separate page-object class for this pop-up?(as this is not a Page). Pop-up has 3 options and a Next button to proceed.
Please read this Martin Follower's article - Page Object.
A quotation:
Despite the term "page" object, these objects shouldn't usually be
built for each page, but rather for the significant elements on a page
Imagine a page which has over of dozen tabs, panels etc, and each one have a few fields, buttons etc. It would be impractical to create a huge class for such a page, it would certainly have 300-500 or more lines of code. Such a class would be very hard to maintain.
It's better (in my opinion) to create several small classes (page objects), each for a specific section of the page, each one containing only a few elements, each no more than 50-100 lines of code. We call these classes page fragments instead of page objects, but the concept is the same.
But it will vary from person to person and everyone may have a different opinion on this topic.
I agree with Bill, however I handle my popups a bit differently. I have it as it's own page object within the same class if it is a page specific popup.
For instance, if you have a popup on your dashboard page that is page specific to the dashboard page but not found anywhere else in the web application, I make it it's own class within the dashboard page object.
The reason I do this is I find the tests far more readable when the specific areas of the application are "containerized" within their own objects. Then when you open the popup and do operations on it, they would look like "popup.SetValue" versus "dashboard.SetValue" or something similar to that. Doing it this way you know that you are doing operations on the popup versus testing the dashboard.
If the popups are widespread throughout your application and can be reused easiliy I would suggest making it into it's own Page Object.
There's not really a hard and fast rule. As others have stated, the page object doesn't have to be a page. It really should be any piece of reusable functionality such as a dialog or header or footer, etc. For automation that I have written, I decided to follow the rule that any dialog is a separate page object (actual separate file). I find that it helps me keep track of pages/dialogs, etc.
To further help with this, I name my classes *Page for pages (e.g. LoginPage.cs), *Dialog for dialogs (e.g. AddImageDialog.cs), *Panel for panels (e.g. HeaderPanel.cs), and so on.
If a dialog only exists on a particular page, I named it based on the base page name, e.g. ProductDetailsPage_AddImageDialog.cs. What that does is when I look at the list of files, they will sort in alphabetical order so all the page objects related to the product details page will sort together so I can quickly see how many page objects are associated with that page and what they are. Some examples are below. You can look through the list and quickly determine which page objects are associated with a particular page and which ones aren't.
HeaderPanel.cs
LoginDialog.cs
ProductDetailsPage.cs
ProductDetailsPage_AddImageDialog.cs
ProductDetailsPage_AddTextDialog.cs
ProductDetailsPage_SaveCompleteDialog.cs
ProductDetailsPage_SaveYourProjectDialog.cs
If a dialog occurs multiple times throughout the site (not associated with a single page), I name it as a standalone page object, e.g. LoginDialog.
I used to just name the page object after the dialog, panel, etc. but after you get 50 page objects, it's hard to remember where certain dialogs occur so I came up with the _ naming scheme and it has helped significantly.
I also considered creating the AddImageDialog page class inside of the ProductDetailsPage page class but when you get larger pages with lots of dialogs, it just makes the file bigger and bigger. I prefer to keep the file size as small as is reasonably possible while keeping all the important bits in there. Breaking the files down into pages and dialogs and having them separate maintains the page object model principles while keeping things cleaner... at least in my opinion.
If the pop-up has an ID locator, and is likely to happen on other web pages, I would put it in its own page object, but often the pop-up is tied directly to the current page and would therefore be better included in that page's object definition.
The only reason I would consider putting it in a separate page object is if it did get used in other pages AND used the same ID locator, as if and when that locator changed, you'd only have to edit the one page object instead of locating and fixing all other page objects that also refer to that pop-up.

How to add content to a running web page?

I have a project that involves conducting and managing online polls. I have a database set up, and a login/sign up page. After logging in, users are directed to the main page, in my case, "index.jsp". On this main page, I want all the current active polls to be displayed (max 5).
My idea was to have a button, i.e. "Create a new poll", and upon clicking it, the user is redirected to a form where they can create a poll (question and choices) using text fields. Upon clicking submit, the newly created poll should be added on the main page, the "index.jsp" page. And here is where I am stuck. Is it possible to modify and update a page while its running? And if so, how? As in, if a new poll is created, the next user that logs in should be able to see the poll displayed on the main page.
I am using a mix of .jsp, .html files and servlets.
Also, is this a reasonable approach? I thought also about polls being separate from each other. As in, if user goes to */pollno=1, it is able to access poll number one, and so on.

Re: Joomla/PHP/Java/AJAX

I am a DBA, not a web developer. I am trying to build a complex website with Joomla. The user page needs to be interactive without refresh. I am not sure I am using the right words, but here goes.
Assume a user is logged in and a session is started - and we have that data along with the users IP address.
The database is crunching things from other users too, just like this one. As the database works, it generates information to be displayed on EACH users screen in real-time, without the user clicking, without screen refresh, and without the web-page code polling the server at intervals. In fact the user may click a different action from their screen simultaneously, so the user screen cannot be sitting waiting for a reply or polling at predefined intervals. It is basically receiving and transmitting "virutally" at the same time. If this is possible to do, a single piece of code would work and results could be deciphered for the right screen entry point (several boxes).
What can be used to do this? Thanks, Bruce
off cource its possible. make ajax call to link like
"index.php?controller=myController"
and in myController set header of either xml or json and prepare response of AJAX there. and at end of code write $app->close(); to avoide rendering of other modules and content

View Expired issues on mojarra

I have a large richfaces tree and each element in the tree can be selected which loads the content via AJAX and edited which redirects you to a new page. This was working great until I had a particularly large document I was working on and saving no longer worked. You got redirected to the edit page which showed the right content, but trying to "save" any edits resulted in a ViewExpiredException.
I tried tweaking a lot of parameters and eventually arrived at two parameters that fixed it:
com.sun.faces.numberOfViewsInSession
com.sun.faces.numberOfLogicalViews
As far as I can see, the default for each is 15, I set them to a ridiculous 500 and the application works again. Unfortunately because I don't know where the problem is situated and it's a large application I can't show you any relevant code.
But the questions are: what exactly do these parameters do, what could cause me to bump into these exceptions and what are acceptable values?
UPDATE
I'm not entirely sure why the question got downvoted but if it is with regards to the supposed duplicate: I had found that post through google but the link it provides is dead. Except for the bog standard (and vague) definition of the parameters, there does not seem to be much information on them.
When server side state saving is used (which is default) than those two parameters can be used to configure maximum number of logical and actual views.
Logical view is top level view which is created on every GET request (for example when you open page in new browser window or tab, entering address in address bar of browser, iframes...). Each logical view can have some number of associated actual views. Actual views are created as user navigate through your pages with standard JSF mechanisms (for example if you navigate to page returned from action methods in commandButton). Both queues of views use LRU algorithm to decide when view will be removed, and maximum number of those queues are limited by values of these two parameters.
So, com.sun.faces.numberOfViewsInSession defines the maximum number of JSF views stored in the session for per logical view, and com.sun.faces.numberOfLogicalViews defines the maximum number of logical views to store per session.
According to information you provided a suspect that configuration of com.sun.faces.numberOfViewsInSession solved your problem, but you must further investigate why is created so many views.
Additional link:
What are the differences between Server and Client side state saving and what are the benefits/drawbacks of each?

JSF: NUMBER_OF_VIEWS_IN_SESSION and the back button

I've got a memory problem in my application because of AJAX4JSF high memory consumption. So we have decided to set the NUMBER_OF_VIEWS_IN_SESSION to 1 and compromise the back button functionality.
However, after adding the following to the web.xml file, the back button still works.
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>1</param-value>
</context-param>
I would like to understand: How the back button still works?!! I've read that setting the NUMBER_OF_VIEWS_IN_SESSION to 1 looses the browser back button functionality.
Thanks in advance for your help.
I've read that setting the NUMBER_OF_VIEWS_IN_SESSION to 1 loses the browser back button functionality.
Either that article you're reading is babbling nonsense or you've misinterpreted the article. The back button's functionality can in no way be controlled from the server side on.
Perhaps the article meant the fact that you cannot submit the page which is been served from the browser cache by back button anymore because this would result in a ViewExpiredException. You'd need to create a Filter which adds response header to instruct the browser to not cache the page so that pressing the back button would fire a brand new GET request on the page so that you won't get a ViewExpiredException anymore when submitting a form on that page.
As to the high memory consumption, I suspect that your problem is caused by something else. Perhaps you're just cobbling too many data in a view or session scoped bean. Read this thoroughly: Why JSF saves the state of UI components on server? Last, but not least, run a profiler before making assumptions.

Categories

Resources