I'm working with a gwt multipage project which I used these code to switch between html pages, for this case switching from index.html to signup.html page:
public static native void fireChangePage(String url)/*-{
$wnd.location.href = url;
}-*/;
public void goToSignUpPage(boolean isDeployed) {
String url = (isDeployed == true ? "signup.html" : "signup.html?gwt.codesvr=127.0.0.1:9997");
fireChangePage(url);
}
I'm getting error 404 when fireChangePage is called from the EntryPoint for the index.html.
Manually changing the url on the browser say: index.html?gwt.codesvr=127.0.0.1:9997 to signup.html?gwt.codesvr=127.0.0.1:9997 works, so I can say that the problem is with the native function fireChangePage.
What could be the problem with the native function? Or is there a better approach than this?
If it's GWT project, you should switch between places (using PlaceController) instead of switching between HTML pages . Anyway, if you have to do so, I'd recommend to use com.google.gwt.user.client.Window.Location class instead (it's provided by framework and works fine).
Try adding slash to the path of the document, i.e. /signup.html.
Related
I am trying to open a new window with the below code. It opens a new window but it has the url as "about:blank". How to change the this url and give a custom url.
private native void openPrintWindow(String contents) /*-{
var printWindow = window.open("", "PrintWin", false);
printWindow.document.open("text/html","replace");
if (printWindow && printWindow.top) {
printWindow.document.write(contents);
} else {
alert("The print feature works by opening a popup window, but our popup window was blocked by your browser. If you can disable the blocker temporarily, you'll be able to print here. Sorry!");
}
}-*/;
It is empty, because first parameter of window.open method is an empty string. Check some examples here. So it should be something like this:
window.open("https://stackoverflow.com", "PrintWin", false);
From Your code I see You want to open a new window by custom URL with some HTML content inside. You cannot do it this way. If You put some URL, the browser will try to open this URL by making a GET request.
Solution to what You want to achieve is to do it more-or-less the MVC way (please note it is NOT a fully correct MVC solution, just a guidance):
Before You open the window, You need to store a content somewhere (best option is on a server side, but there is also a way to store it on a client side)
Create a new page, accessible via Your custom URL (either a simple HTML or a service, up to Your needs).
You need to write some code in this new page which will retrieve Your content (stored previously somewhere) and present it in this newly opened window.
i am using GWT app engine to deploy my application in local host.
i want to redirect to second page when user completed his registration & clicked "submit" button, the browser has to redirect to automatically to his Profile page with his registration details.
i used fallowing code to redirect to second page from first page;
String url = GWT.getHostPageBaseURL()+"/UserViewProfile.html";
Window.Location.replace(url);
in my case the first page is URL is like:
http://127.0.0.1:8888/UserRegistration.html?gwt.codesvr=127.0.0.1:9997
when i submitted on "Submit" button it is edirecting to URL like:
http://127.0.0.1:8888/UserViewProfile.html
In second page(UserViewProfile.html) i developed simple HTML content & simple Textbox widget to check it's functionality. But i am seeing HTML content only but not "Textbox".
To see text box i has to type URL like:
http://127.0.0.1:8888/UserViewProfile.html?gwt.codesvr=127.0.0.1:9997
how i can access last part "?gwt.codesvr=127.0.0.1:9997" at end of my URL pattern automatically? if i add it manually, at the time of hosting it may leads to problem. please if any body give solution, that would be great.
I do not understand the use case. Anyway I guess you need to conditionally check if you are in DevMode or ProdMode, and add the gwt.codesvr=127.0.0.1:9997 query string accordingly. Something like:
String url = GWT.getHostPageBaseURL()+ "/UserViewProfile.html";
if (GWT.isProdMode()) {
Window.Location.replace(url);
} else {
Window.Location.replace(url + "?gwt.codesvr=127.0.0.1:9997");
}
The gwt.codesvr=127.0.0.1:9997 query string parameter is used by GWT to (simplifying) bootstrap your app in the so called Development Mode, instead of the Production Mode (the actual compiled version of your application). Without this check, if you are in DevMode, you end up requesting the UserViewProfile.html that looks for the compiled version of your app (that does not show anything, if you've never compiled it, or if you have simply recently clean the project).
Do also note that URL rewriting (by not simply changing the # fragment identifier), means application reloading.
default form in wicket looks like
private class TournamentWebForm extends Form<Void> {
private static final long serialVersionUID = 1L;
public TournamentWebForm() {
super("tournamentForm");
// add componets ...
}
and then page looks like (important is number behind ?)
http://localhost:8080/tournament-system-web/home?19
but on the internet I found this page which is written in wicket too:
http://jizdenky.studentagency.cz/?wicket:interface=wicket-0:3:3:::
and when I search for ticket their form looks like:
http://jizdenky.studentagency.cz/Booking/from/BRNO/to/PRAHA/tarif/REGULAR/departure/20121213/retdep/20121213/return/false/ropen/false/credit/false/class/2.5#search-results
how I can create this form ?
UPDATE:
It look like that what page is return depends on last parameter in this case: #search-results how I can implement these feature ?
You don 't.
What you see on the link above is the URL Wicket prior to version 1.5 created for statefull pages.
The secound URL is that of a BookmarkablePage with URL Parameters. See mounting pages
Follow the procedure in the link and pass the page parameters to your form via standard java options.
Have you read about page parameters? You can find out something by visiting Apache Wicket's home page, and then following Reference guide, Wicket reference, Pages.
Enjoy?
I'm new to Wicket and have made an application using some tutorials.
How do I create a servlet and pass on the input from that to a web page without database transactions?
I'm assuming you are trying redirect to a Wicket page (parameterized) from outside the Wicket application.
You can do this by using one of the URL encoding strategies (BookmarkablePageRequestTargetUrlCodingStrategy, QueryStringUrlCodingStrategy, ...) which will give that page a clean URL which can be referenced easily. Or you can put a BookmarkablePageLink in your web application somewhere, copy the link that it generates and use it to redirect to.
You can reference that link anywhere you wish passing parameters to it using the normal ?par1=val&par2=val system.
To read these parameters in your page you will need to define your page constructor like so:
...
public MyPage(final PageParameters parameters) {
final String par1 = parameters.getString("par1");
final String par2 = parameters.getString("par2");
}
...
Can i change url(set parameter) without submit?
I found this method
http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/user/client/Window.Location.html#replace%28java.lang.String%29
but it submit page. All GWT state will be lost.
If you want to change something that is not in the hash, for example you want to change a parameter in the URL, you can do it like this!
private void someMethod() {
String newURL = Window.Location.createUrlBuilder().setParameter("someParam", "someValue").buildString();
updateURLWithoutReloading(newURL);
}
private static native void updateURLWithoutReloading(String newUrl) /*-{
$wnd.history.pushState(newUrl, "", newUrl);
}-*/;
Then you could register a function that handles the user using the back and forward browser buttons as demonstrated here.
Why are you trying to do this? Generally speaking, GWT apps don't change pages - thus they are normally SPAs (single page applications)
When you load a new page from a server, you will lose the state on that page. You can change the hash part of the URL as that won't return to the server, like this:
String newURL = Window.Location.createUrlBuilder().setHash("newhash").buildString();
Window.Location.replace(newURL);
However, if you're going to do this, I would recommend taking a look at GWT's MVP framework, which has built in support for managing locations using hash tokens.
http://code.google.com/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html
$wnd.history.pushState(newUrl, "", newUrl);
Works nicely in HTML5-browsers. Not in IE8 or IE9!