Wicket Page cahing in DefaultPageStore - caching

Recently I've overridden Wicket's DefaultPageStore methods serializePage and deserializePage and enhanced them with logging to track time spent in them.
I discovered that deserializePage is never called because the actual page is always retrieved from the SessionEntry#sessionCache.
I suspect this is due to my page setting setVersionPagesByDefault(false) which creates the situation where there is only current version of a page which is serialized in the SessionEntry and then (needlessly) in the DefaultPageStore from where it's never deserialized.
If this suspicion is correct, I'm then able to make method serializePage a no-op a and skip serialization, which currently takes 3 or 7 seconds (DeflatedJavaSerializer) for page X.
I did not detect any side-effects so far, so my question is: is this safe? And if not, then why?
I'm considering this only as temporary solution until I'm able to move the data from the page to proper cache.

Here is some info on page versioning: http://wicket.apache.org/guide/guide/versioningCaching.html
If you do not need support for back button, you can disable page versioning - it has not side effects, assuming that your pages handle back button correctly. Jumping back to the page that has no state can create page without initial parameters. Like for example: you jump from page A to B and provide some arguments to B. Now user is on page C and clicks back button. This will result in redirect to page B, but no arguments will be passed this time. If you would use page versioning, wicket would only deserialize page B and execute rendering again.
Here is also one possibility to disable page store:
http://maciej-miklas.blogspot.de/2013/09/wicket-6-disable-page-serialization.html

Related

Can I delay loading of some controls on an xPage to after page loaded

is it possible to delay loading of some controls on an xpage?
This is the problem: let's say you have a control that does a fultextsearch and displays the result in a repeat control. this ft search might take a long time and will hold the webpage loading in a waiting state until the search result is ready.
I want my page to load most of the data initally, and some "time consuming" controls should be loaded in to the page as a sperate request after the inital load.
this way the user will immediatly see the webpage, but some of the data on the page will load a little bit later without holding the webpage in a waiting state from the server.
possible?
The downside to using rendered is that all the value bindings will still evaluate, even if the corresponding markup isn't sent to the page. So the trick here is making sure the components don't even exist until you want them to.
Every component has a getChildren() method. This returns a mutable List of components, which has a add() method. This allows you to add components to the page on the fly, either while the page is loading, or later during an event. For the purposes of what you're trying to do, you would want to defer adding the "expensive" components until a subsequent event.
Create an event handler attached directly to the view root (), give it a unique ID (e.g. "loadExpensiveComponentsEvent", set its refresh mode to partial, set a refresh ID to whatever div or panel will contain the search results, and set its event name to an arbitrary event (e.g. "loadExpensiveComponents"). This prevents your event from being triggered by actual user behavior. Set the event's code to SSJS that will inject your components.
Then add a script block () to trigger the event after the page has loaded:
XSP.addOnLoad(function(){
XSP.firePartial(null, "#{id:loadExpensiveComponentsEvent}");
});
Your page will load without the search result components. Once the page has fully loaded, it will trigger the component injection event automatically.
For guidance on how to code the injection event, open the Java file that has been generated from your existing page to see what components need to be injected and what to set their values to.
You can pack them into a panel and set their rendered status to rendered=#{viewScope.pageFullyLoaded}. Then in the onLoad event have a XSP. partialRefresh request where you set viewScope.pageFullyLoaded=true
A little ugly but doable. Now you can wrap that code into your own custom control, so you could have a "lazyGrid", "lazyPanel" etc.
Not sure why I did not think of this before. the dynamic content control in extlib actually solves this problem. the dcc can be triggered onClientLoad both using javascript and ssjs afer the page has loaded.
one problem I am facing now is that I am already using the dcc on my site so I need to put another dcc within my dcc. and this seem to be a bit buggy. I have reported it to the extlib team on openNTF.

Problem showing a messaje to the user using ASP MVC TempData

I'm using TempData to show a message to the user. I put a string in the TempData and later I read the string, and if it is not empty, then I show a DIV that contain the message.
All works fine, and if the user refresh the page the message are not shown (Thats what I want). The problem is that if the user navigate to other page and then press the back button in the browser, then the message are shown again, and I do not want this.
What could I do to avoid this behaviour?
Thanks.
This is the code I use to read the TempData (Razor + VB). There is a DIV #commonMessage, with this code I put the string inside the div and show it. As I said before, it's working, but the only problem is that the TempData is still there if the user click back in the browser.
#If Not IsNothing(TempData("MessageUser")) AndAlso TempData("MessageUser") <> String.Empty Then
Dim str As String = TempData("MessageUser")
#<script type="text/javascript">
$(document).ready(function () {
$('#commonMessage').html("#str");
$('#commonMessage').delay(400).slideDown(400).delay(4000).slideUp(400);
})
</script>
End If
EDIT: Seems like the TempData are being catched, because if I Disable the cache for the action where I'm showing the message (Using the Attribute System.Web.Mvc.OutputCache(NoStore:=True, Duration:=0, VaryByParam:="*")) the problem dissapears. But It would be better I we could find a method that not involve disabling the cache...
REQUESTED EDIT: I'm very newby in ASP, so I try to clarify what i'm triying to do. When an user performs an action (edit a client, for example), I redirect the client to the client list page, and I show a message that tell to the user "The client data was update susessfully". I'm triying to do it in a way that makes the message to be show only once. Maybe the TempData is not the right way (I don't know, 'cos i'm learning yet), but the target is to show a message to an user only once (no matter if the urser refresh or if the user go to other page and then press back in the browser)... using TempData or using something more adequate to our purpose.
Essentially, you are wanting TempData to do what you want, rather than using the right tool for what you want.
TempData is, by design, intended to be used for caching data across HTTP redirections. That is what it exists for. It is not clear from your post if this is the scenario that you are using.
Ie:
Page redirection, with data in TempData, that is then displayed to the user. Refresh the page you have arrived on, and the TempData is no longer there (there has been no redirection, just a refresh).
If the user then navigates to another page, then uses the back button, the browser will have cached the html of your page and will redisplay that. That is the correct behaviour.
I also think that in your testing, you are getting it wrong. Ie, by disabling the caching, you are just knocking out TempData altogether and you will not get the correct behaviour. Ie, the message will NEVER appear, not just when you hit the back button.
Your jQuery looks inefficient. You are making it do things it doesn't need to do. You could use razor to populate your div with your message. Set the div to not display, ie:
<div id="commonMessage" style="display:none;">
Then use jQuery to show it:
$('#commonMessage').show();
Your post isn't that clear, but in summary, I would say you are seeing what you should.
Maybe you should describe, in an Edit, what you want your app to do. That way it would be easier to answer. As things stand, you have told us what happens and what you put in your view, but it is not clear what you expect.
You should also understand TempData better: it only persists between Controller actions, ie, when a redirect occurs. It stores its data in the Session store, which I believe is affected by the caching attribute you mention.

Using Watir on Peoplesoft App: each text field reloads the page

I'm using Watir 1.6.7.
I'm working on developing some regression tests for a PeopleSoft App using Watir and Cucumber. I have run into a few issues with forms in the application.
First, when entering a value into a text_field, the page refreshes when the user clicks outside the text_field. Waiting for the next text_field element to exist is problematic because it may locate the element before the page reloads, or after the page reloads as expected. Increasing the wait time never feels like a good solution, even though it "works".
The second issue is that the page refresh is not triggered until the user clicks outside the current field. In this case, that happens when the script tries to access the next text_field to be populated. One solution here would be to send a or keystroke, but I can feel the script becoming more brittle with every addition like this.
Are there any other approaches that would be less brittle, and not require 2-3 extra commands in between each text_field action?
The play-by-play looks like:
Browser navigates to page that contains the form.
Browser fills in first form field. (fix: send keystroke to cause page refresh, wait_until second field is visible again)
Browser selects the second form field to be filled out. (again, keystroke & wait_until)
Page refreshes, script fails. (resolved)
Browser selects the third form field...
The application started exceeding the 5 second sleep duration, and I did not want to increase the wait time any longer. I wanted to see what would happen if I populated the text field faster using "element.value =" rather than character by character with "element.set ".
This change completely resolved all complications. The page no longer refreshes when entering text, and no long requires a send_keys statement to use TAB or ENTER to move to another field. The form is storing all of the data entered even though there are no refreshes or state saves between fields.
Previous method:
def enter_text(element, text)
element.set text
#browser.send_keys("+{TAB}")
sleep 5
Watir:Wait.until { element.exists? }
end
New method:
def enter_text(element, text)
element.value = text
end
Firstly, there are interesting Wait methods here: How do I use Watir::Waiter::wait_until to force Chrome to wait?
Overall, I don't quite understand your problem. As I understand it your script is working. If you could be a bit clearer about your desires compared to what you already have that would help, as would some sample source code.
If you're looking for ideas on custom waiting you could check for changes in the HTML of your page, form or text field. You could check that the text field is .visible?. You could try accessing the next text_field (clicking it, or setting the value for example), then catch the exception if it can't find the text_field and retry until it doesn't break, which would solve both your problems at once.
Why would clicking outside the current field be a bad solution? Do you absolutely need the next step to be a text_field access? I haven't gotten my head around how the next field only exists when you click outside the current field, but you cause this refresh by accessing the next field.
Edit: Most welcome, and thank you for clearing that up, I think I now understand better. If you allow Watir to invoke its page wait, or force it to, then it will wait for the refresh and you can then find the new text_field. Keystrokes do not invoke ie.wait, so if you send a single keystroke, then invoke a wait then the rest of your script will be responding to the post-refresh state.
I highly recommend the OpenQA page on waiting in Watir. If what you're doing to invoke the refresh does not appear on the list of things that invoke Watir page waits then you need to invoke your own page wait... but you need to do it before the page refreshes, so the cause of the refresh should end before the end of the refresh itself.
I don't know peoplesoft's app well enough to know this, but Does the app display anything for the user while it's processing.. like some kind of little 'loading' graphic or anything that you might be able to key off of to tell when it's done?
I've seen apps that do this, and the item is just an animated gif or png and it is displayed by altering the visibility attribute of the div that contains the graphic. In that instance you can tell if the app is still loading by using the .visible? method on that element and sleeping for a while if it's still there.
for the app I'm testing (which has one of those 'icons') I created a simple method I called sleepwhileloading. all it that is does is use a one second sleep wrapped in a while loop that looks to see if the loading icon is visible. works like a charm

Transfer Full Control (Navigation)

My question was little diff.
From MainPage.xaml, I am using 'NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));'. It does not goes to Page1.xaml immediately. It just creates an Now the control does not completely goes to Page1.xaml. It again starts execution what is written on the next line to NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative)).
I have to transfer full control towards Page1.xaml, when I return from Page1 then it must resume the remaining execution of MainPage.xaml.
Plz Help.
Navigating to another page is not a synchronous process where you call the page and wait for a return result.
When you pass control to another page, it is effectively something that you fire off and forget.
Any subsequent processing you want to do when you get control back in the original page should be handled in one of the corresponding events/overrides for that page - Loaded, OnNavigatedTo for example.
So when the user navigates back from Page1, you want to do something on MainPage? Override OnNavigatedTo in MainPage and handle the navigation that way. I don't think there's a really elegant way to determining that the navigation was due to a "backward" navigation - you may need to use PhoneApplicationService.Current.State to work that out.
Note that this due to tombstoning etc, this could be a different instance of MainPage from the original one.
Either way, you won't be able to just continue from where you left off within a method. You need to think in a more event-based way.

(ASP.NET AJAX) How do you disable the ticker after it fires an event?

So i'm implementing a feature where after a user has visited my site, and not signed in and not registered for over two minutes, an alert pops up and asks them to take a survey.
I agree, annoying, but it's a business requirement.
I thought about doing a Session Object, and then in the page_load of the header (since it's on every page) check if the current time is greater than the time in session.
However, this will only fire when the page loads. I kind of need it to pop up at exactly tw minutes.
So I looked into the ASP.NET AJAX timer, which seems to do the trick.
My question is how do you disable it? Because now it just keeps firing every 20 seconds which is what my current interval is.
I thought about maybe setting a cookie and if the cookie isn't present show it, otherwise don't.
Just wondering if anyone else had any insight into this.
Thanks guys!
The problem with the setTimeout() approach as shown by azamsharp is that it only works if the user stays on the same page during the two minutes.
If you have different pages, the you will probably have to implement a solution involving the asp.net session and client-side scripting, e.g:
store a DateTime in the session when the alert must be shown
(on every page) call a page-method from javascript (e.g. every 5 seconds) to check if the alert is due, and show it if it is due
put the javascript part (the call of the pagemethod) into a common master page and use this for each asp.net page
You can use the JavaScript windows.setTimeOut method which will fire exactly once after whatever time is specified.
window.setTimeOut(foo,2000);
The above will call the foo JavaScript function after 2 seconds.
Thanks,

Resources