In wicket, how to make the page re-init when back button is hit - wicket

I'm using Wicket 6, and we have a situation where a user is hitting back and it's loading the page without initializing it from the page history. I want the page init to run so that data is read fresh and things are in the proper state. How can I make wicket do this?
I thought I was already doing this with a custom MountedMapper that someone had suggested long ago, but I have a breakpoint in the page constructor (the one that accepts PageParameters) and it's not running.
The custom MountedMapper:
if (requestHandler instanceof ListenerInterfaceRequestHandler || requestHandler instanceof BookmarkableListenerInterfaceRequestHandler) {
return null;
} else {
return super.mapHandler(requestHandler);
}

You could make your page stateless, so it is recreated on each access.
Or improved your page, so that it loads fresh data on each render:
either use appropriate models that automatically deliver up-to-date data or override #onConfigure() and update,

Related

Wicket implement flash redirection

I would like to perform something like a flash redirection (not sure if it is really called flash redirection).
After a certain action like delete device, I am redirecting to the device list page.
Now, for the redirect URL... I am appending &sdr=true and it works.
The problem is... that parameter (&sdr=true) stays there even after just refreshing the page.
If I remember it correctly, when I do flash refresh... the parameter stays there but will disappear on refresh... or just good for one refresh only.
Below is my method for redirection:
public static void redirect(String redirectUrl) {
throw new RedirectToUrlException(redirectUrl);
}
now, how do I implement the flash redirection in wicket? I am using wicket 6 version.
Or... I would like the parameter &sdr=true be good only for 1 request. When the page is refreshed or reloaded... it should be gone.
Thanks :)
Sorry if this question is very easy, I am really new to wicket
May be there is another solution for your problem.
Wicket could be stateful, i.e. it can keep state between the pages navigation. So you can do:
setResponsePage(new SomePage(someState));
this way there is no need to pass anything in the url and SomePage's constructor can decide what to do with the passed state.
If you prefer to add request parameter in the url then you may use
PageParameters params = new PageParameters();
params.put("sdr", "true");
setResponsePage(SomePage.class, params);
In SomePage's constructor you will need to remove the sdr parameter from the passed PageParameters so that it is not rendered in all urls inside the page, e.g. in links, form action, etc.
But if you want the parameter to disappear in a page refresh/reload then you will need to make another redirect:
public SomePage(PageParameters params) {
super(params);
StringValue srdValue = params.get("srd");
if (!srdValue.isNull()) {
params.remove("srd");
// do something custom
throw new RestartResponseException(this);
// or throw new RestartResponseException(getPageClass(), params);
}
}

How to integrate Google Identity Toolkit with a single webpage app (e.g. GWT)

I need to integrate Google's identitytoolkit (Google's identitytoolkit) with my Google webtoolkit (GWT) application.
However rendering the gitkit signInButton or widget is already not straightforward because the way to do it is linked to "window.onload". And I need to render the widget at a later moment.
I managed to do it (see below), but I am not happy with this and I wonder if someone else found a better way of integration.
private native void showGitKitWidget() /*-{
$wnd.google.identitytoolkit.signInButton(
'#gitkitDivId', // accepts any CSS selector
{
widgetUrl: "//127.0.0.1:8888/gitkit/signin.html",
signOutUrl: "/gitkit/signout",
popupMode: true
}
);
var evt = $doc.createEvent('Event');
evt.initEvent('load', false, false);
$wnd.dispatchEvent(evt);
}-*/;
Update
Actually using the popupMode parameter for the signInButton makes a seamless integration even closer. This lets the widget popup in a browser window and leaving the GWT window unchanged. Then in the widget instead of redirecting to the successUrl I use the JS callback to trigger an AJAX call instead.
var config = {
idps: ["googleplus"],
signInSuccessUrl: '//127.0.0.1:8888/gwt/servlet/gitkit/signedin',
callbacks: {
signInSuccess: function(tokenString, accountInfo,
opt_signInSuccessUrl) {
/* !!! Tell GWT parent window that we are ready...
I believe using a cookie for which the parent is
regularly looking is the way to go, because it
will work in mobile browsers too.
*/
return false; // prevents redirect to signInSuccessUrl
}
}
Update Finally the GWT parent window will wait for the result cookie and if found make the AJAX call to the signInSuccessUrl. It will also have to render the signInButton again, which will then show the signed in user.
So the only ugly workaround is how the signInButton is rendered using the onload method call.
It would be very helpful if there would be a way to render the signInButton dynamically when needed, for instance if there were a "$wnd.google.identitytoolkit.update()" method. This could be called any time for the first time and should also be able to handle signin-status change!
In conclusion, I have answered my own question, which might be helpful to others, but also I would still like to ask if there would be a better way, which I missed.
As you've noted, the Identity Toolkit widget currently needs to be triggered by page load. Single-page applications (like those built with GWT) should place the widget on a separate page. Then you can redirect the user there - or render via popup, as you've noted - to sign in the user in.
If rendering the sign-in button is a problem, there is documentation on how to load the widget directly.

protractor - how to enforce protractor to wait for REST call to return information to complete building page elements

New to testing with protractor, actually new to test automation in general so hopefully this is posted in the right place. Apologies if not, please advise.
I am trying to test elements on a pages which are only displayed after a response to REST call. The page in question has two TABS, I click on the non-active TAB, it goes active, loads the TAB framework, then a few seconds (depending on the information returned) later a Graphical timeline is built in the TAB based upon the information from the REST call.
My problem is how to make protractor wait for the REST call to be completed and the Timeline built before continuing to test the elements in the Timeline.
From various searches I am using the following code. I am just picking a single element on the Timeline to check for isPresent. I have also tried using browser.wait as opposed to ptor.getInstance however have the same problem that the wait is not waiting for the timeline to load fully. Any guidance would be much appreciated.
it('XXXXXX', function() {
var ptor = protractor.getInstance();
// Define element to wait for in the Timeline Graphic
var waitForElement = by.css('.timeline-time');
// Load the page
jobManagerPage.go();
// Click the inactive TAB to make active
jobManagerPage.eleDataVisTabLiTag.click();
// This is where I am expecting to wait for the element in the Timeline
// to be present before continuing
browser.wait(function() { return ptor.isElementPresent(waitForElement);
}, 8000);
// Test for the Timeline element to be present - this keeps failing !!!!!
expect(ptor.isElementPresent(waitForElement)).toBeTruthy();
});
One solution (though far from ideal) is to add an element to the DOM when you're loading, and remove it when done (or add/remove a CSS class, etc...). You may or may not have the opportunity to do that, depending on how your AJAX calls are being made.
I found this approach in an answer to this SO question: AngularJS + Protractor wait for all ajax calls to end / full page load, before running the tests

How to prevent code to execute after firing of history token in gwt?

I am working on gwt2.3 application with gwtp framework.In this application I am have one login (index) page which is bind by the client module.
bindConstant().annotatedWith(DefaultPlace.class).to(NameTokens.login);
Now after successfull login a new name token name user page is fired.
History.newItem(NameTokens.userconsole,true);
Now I have my history handler like below:
public class NameTokenHandler implements ValueChangeHandler {
#Override
public void onValueChange(final ValueChangeEvent<String> event) {
System.out.println("Nothing to do");
}
}
And I added to History like below in entry point class:
History.addValueChangeHandler(new NameTokenHandler());
Now as I have overridden the onValueChange method & I have left it blank.
So when application loads first or any other name token fires it should invoke onValueChange first
and as there no code in this method nothing should be load.
But in application it is working fine. All the name tokens are firing successfully even after there is no code in onValueChange. I am not getting how to prevent the firing of history token?
Please help me out.
Thanks in advance.
So when application loads first or any other name token fires it should invoke onValueChange first and as there no code in this method nothing should be load.
If you are using gwtp History ValueChangeHandler will not prevent or enable navigation to a particualr part of your application. That is all handled with PlaceManager.
After some googling I came to know about place manager.
I am adding_ a change handler to History. All the change handlers that
have been added already are still there. In particular, the one in GWTP's
PlaceManagerImpl constructor.
If you really want to prevent some history events from being handled by
GWTP, I would suggest that, in your custom PlaceManager, you
override onValueChange(...), intercept the tokens you want to block, and
call the parent's onValueChange for the tokens you want GWTP to handle
normally.

How To Redirect From a Control Using MVC2

I have been tasked with creating a user control to live in our master page that allows users to switch between accounts. This way, we can allow users to change their account without having to go back to the accounts page. This seemed like a legitimate and perfectly straightforward task.
I've built the control and added it to the master page using Html.RenderAction. The last step is for me to redirect the user to the home page for that account. In order to do this, I build a route to the home page and attempt return RedirectToRoute(route).
When I attempt this, I get this error:
Child actions are not allowed to perform redirect actions
Anyone have any ideas on how to resolve this or have I coded myself into a box
Thanks in advance
You can cheat with an ugly hack:
[ChildActionOnly]
public ActionResult SomeUserControlAction()
{
// ... some processing
var url = Url.RouteUrl("routeName", new
{
action = "foo",
controller = "bar"
});
Response.Redirect(url);
return null;
}
It's so ugly that I feel ashamed for even mentioning it, but it works.
Another possibility would be to pass the url as part of the view model to the view and perform the redirect in javascript by setting window.location.href to the new url.