Using Google Web Toolkit, I'd like to code the equivalent of a hard refresh (control + F5).
I don't believe (or know) if GWT's Window.Location will work.
import com.google.gwt.user.client.Window.Location;
Window.Location = currentPage; // I don't think it'll be hard refresh
For reloading the current page you need to call Window.Location.reload() method.
Reloads the current browser window. All GWT state will be lost.
Or you can even specify your own JSNI (below how todo), because by default force reload is false :
public static native void forceReload() /*-{
$wnd.location.reload(true);
}-*/;
According to https://developer.mozilla.org/en-US/docs/DOM/window.location#Methods you would need to call window.location.reload(true) to force the reload of the current page.
Unfortunately GWT wraps only the window.location.reload() via Window.Location.reload(), and it is up to the browser to retrieve the page from the cache or from another get. This is done to achieve the most cross-browser solution.
Never tried but you should be able to use the following.
public static native void reload(boolean force) /*-{
$wnd.location.reload(force);
}-*/;
For reload gwt page, you have two options:
1) Window.Location.reload();
Reloads the current browser window. All GWT state will be lost.
2) Window.Location.replace("newurl");
Replaces the current URL with a new one. All GWT state will be lost. In the browser's history, the current URL will be replaced by the new URL.
Related
I am using Spring Webflow and I am redirecting from a view-state to action-state to view-state. Now, when the user is on second view-state, I don't want the user to be able to click the browser back button and go to the previous page.
I found that, history="invalidate" can be used to invalidate the snapshot of previous page. I tried using it in the transition. However, its not working (the browser back button is not disabled).
So, what can I add to my webflow states in order to disable the back button and only allow the user to use the navigation controls provided inside the page?
Thank you
To which state did you add the history attribute?
First, <action-state> doesn't support it (https://jira.spring.io/browse/SWF-1481).
You'd have to add it to the first <view-state>'s transition. Which, if you only wanted to do it conditionally on something that happened in the <action-state>, wouldn't be sufficient. We ended up creating Java code to call from our <action-state> method to do this.
/**
* Invalidate WebFlow history. For use in action-state, where the transition element is not able
* to specify to invalidate history.
*/
public static void invalidateHistory() {
RequestContext context = RequestContextHolder.getRequestContext();
synchronized(context.getFlowExecutionContext()) {
DefaultFlowExecutionRepository r =
(DefaultFlowExecutionRepository)
((FlowExecutorImpl)
context.getActiveFlow().
getApplicationContext().
getBean(FlowExecutor.class)).getExecutionRepository();
r.removeAllFlowExecutionSnapshots((FlowExecution)context.getFlowExecutionContext());
}
}
(Also, note that "invalidate" invalidates the state and all before it. If you only want to prevent that single state, you'd use "discard" instead. https://docs.spring.io/spring-webflow/docs/current/reference/html/views.html#view-backtracking)
What is the difference of placing a Javascript (.js) library on before the GWT application nocache.js and after nocache.js in a GWT application which uses the JS library in JSNI methods.
Does it affect wether a JSNI method will be functional or not?
That really depends on when the JSNI method is loaded.
To be safe - always check to see if the JS lib you are using has been loaded. eg
public native static boolean isJqueryMethodLoaded(String method) /*-{
if ($wnd.jQuery && $wnd.jQuery[method]) {
return true;
} else {
return false;
}
}-*/;
(edited - thanks to the other answers for clarifying the load sequence)
Normal <script> tag are blocking, but the GWT script tag is not, since it is fetched asynchronously (i.e., non-blocking). The onModuleLoad() is called only when the body has been parsed (i.e., scripts have been fetched). Hence:
put it as the very first script in your list: you will save time;
<script> tags will always be loaded when onModuleLoad() is called.
Have a look at here.
onModuleLoad is always called at or after DOMContentLoaded, and this will always happen after your scripts have loaded (because they could do document.write()), unless you loaded them with async or defer.
So, unless you load your "other JS" with async or defer, it really shouldn't matter in which order you load them, as onModuleLoad should always be called after both are loaded.
I'm working on an Eclipse based application in which we use a Browser widget.
When typing text in this widget, a spell check is executed. We would like to deactivate it.
Is it possible ?
If you have control over the page that is displayed, you can simply disable spell checking by setting the appropriate attribute(s) (see
Disable spell-checking on HTML textfields). But I think you wouldn't have asked if that was the case...
If however the page is loaded from elsewhere you need to let the browser widget execute Javascript code that disables spell checking after the page is fully loaded.
The snippet below uses a ProgressListener to that is called when the page has been loaded completely. The Javascript that then gets executed is off the top of my head and may need refinement.
Browser browser = new Browser( parent, SWT.NONE );
browser.addProgressListener( new ProgressAdapter() {
public void completed( ProgressEvent event ) {
browser.execute( "document.getElementsByTagName( 'html' )[ 0 ].spellcheck = false;" );
}
} );
browser.setUrl( ... );
I am using htmlunit in jython and am having trouble selecting a pull down link. The page I am going to has a table with other ajax links, and I can click on them and move around and it seems okay but I can't seem to figure out how to click on a pulldown menu that allows for more links on the page(this pulldown affects the ajax table so its not redirecting me or anything).
Here's my code:
selectField1 = page.getElementById("pageNumSelection")
options2 = selectField1.getOptions()
theOption3 = options2[4]
This gets the option I want, I verify its right. so I select it:
MoreOnPage = selectField1.setSelectedAttribute(theOption3, True)
and I am stuck here(not sure if selecting it works or not because I don't get any message, but I'm not sure what to do next. How do I refresh the page to see the larger list? When clicking on links all you have to do is find the link and then select linkNameVariable.click() into a variable and it works. but I'm not sure how to refresh a pulldown. when I try to use the webclient to create an xml page based on the the select variable, I still get the old page.
to make it a bit easier, I used htmlunit scripter and got some code that should work but its java and I'm not sure how to port it to jython. Here it is:
try
{
page = webClient.getPage( url );
HtmlSelect selectField1 = (HtmlSelect) page.getElementById("pageNumSelection");
List<HtmlOption> options2 = selectField1.getOptions();
HtmlOption theOption3 = null;
for(HtmlOption option: options2)
{
if(option.getText().equals("100") )
{
theOption3 = option;
break;
}
}
selectField1.setSelectedAttribute(theOption3, true );
Have a look at HtmlForm getSelectedByName
HtmlSelect htmlSelect = form.getSelectByName("stuff[1].type");
HtmlOption htmlOption = htmlSelect.getOption(3);
htmlOption.setSelected(true);
Be sure that WebClient.setJavaScriptEnabled is called. The documentation seems to indicate that it is on by default, but I think this is wrong.
Alternatively, you can use WebDriver, which is a framework that supports both HtmlUnit and Selenium. I personally find the syntax easier to deal with than HtmlUnit.
If I understand correctly, the selection of an option in the select box triggers an AJAX calls which, once finished, modifies some part of the page.
The problem here is that since AJAX is, by definition, asynchronous, you can't really know when the call is finished and when you may inspect the page again to find the new content.
HtmlUnit has a class named NicelyResynchronizingAjaxController, which you can pass an instance of to the WebClient's setAjaxController method. As indicated in the javadoc, using this ajax controller will automatically make the asynchronous calls coming from a direct user interaction synchronous instead of asynchronous. Once the setSelectedAttribute method is called, you'll thus be able to see the changed made to the original page.
The other option is to use WebClient's waitForBackgrounfJavascript method after the selection is done, and inspect he page once the background JavaScript has ended, or the timeout has been reached.
This isn't really an answer to the question because I've not used HtmlUnit much before, but you might want to look at Selenium, and in particular Selenium RC. With Selenium RC you are able to control the interactions with a page displayed in a native browser (Firefox for example). It has developer API's for Java and Python amongst others.
I understand that HtmlUnit uses its own javascript and web browser rendering engine and I'm wondering whether that may be a problem.
I'm working on a project where we're using a Java applet for part of the UI (a map, specifically), but building the rest of the UI around the applet in HTML/JavaScript, communicating with the applet through LiveConnect/NPAPI. A little bizarre, I know, but let's presume that setup is not under discussion. I started out planning on using jQuery as my JavaScript framework, but I've run into two issues.
Issue the first:
Selecting the applet doesn't provide access to the applet's methods.
Java:
public class MyApplet extends JApplet {
// ...
public String foo() { return "foo!"; }
}
JavaScript:
var applet = $("#applet-id");
alert(applet.foo());
Running the above JavaScript results in
$("#applet-id").foo is not a function
This is in contrast to Prototype, where the analogous code does work:
var applet = $("applet-id");
alert(applet.foo());
So...where'd the applet methods go?
Issue the second:
There's a known problem with jQuery and applets in Firefox 2: http://www.pengoworks.com/workshop/jquery/bug_applet/jquery_applet_bug.htm
It's a long shot, but does anybody know of a workaround? I suspect this problem isn't fixable, which will mean switching to Prototype.
Thanks for the help!
For the first issue, how about trying
alert( $("#applet-id")[0].foo() );
For the second issue here is a thread with a possible workaround.
Quoting the workaround
// Prevent memory leaks in IE
// And prevent errors on refresh with events like mouseover in other browsers
// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload",
function() {
jQuery("*").add(document).unbind();
});
change that code to:
// Window isn't included so as not to unbind existing unload events
jQuery(window).bind("unload",
function() {
jQuery("*:not('applet, object')").add(document).unbind();
});