GWT: Capturing URL Parameters in a GET Request

I need to create a GWT application that will be called by an external application with specific URL parameters.

For example:

http://www.somehost.com/com.app.client.Order.html?orderId=99999 .

How to capture orderId parameter inside a GWT application?

+53
java gwt
Feb 26 '09 at 13:37
source share
4 answers

Try

String value = com.google.gwt.user.client.Window.Location.getParameter("orderId"); // parse the value to int 

PS GWT can reference its own javascript, which means that if javascript can do this, GWT can do it too; for example in GWT you can write

 public static native void alert(String msg) /*-{ $wnd.alert("Hey I am javascript"); }-*/; 

In this case, you can even use the existing javascript library to retrieve the parameter value in the request.

+83
Feb 26 '09 at 14:03
source share

GWT has the ability to retrieve parameters from a URL:

 String value = Window.Location.getParameter("param"); 

Make sure your URLs are in the form:

http://app.com/?param=value#place instead of http://app.com/#place¶m=value

To get all the parameters on the map, use:

 Map<String, List<String>> map = Window.Location.getParameterMap(); 
+18
Oct 31 '12 at 12:35
source share

I suggest you use GWT MVP . Suppose your URL is like

http: //www.myPageName/myproject.html? #orderId: 99999

And in your AppController.java -

Try it like

  ...... public final void onValueChange(final ValueChangeEvent<String> event) { String token = event.getValue(); if (token != null) { String[] tokens = History.getToken().split(":"); final String token1 = tokens[0]; final String token2 = tokens.length > 1 ? tokens[1] : ""; if (token1.equals("orderId") && tonken2.length > 0) { Long orderId = Long.parseLong(token2); // another your operation } } } ........... 

Alternatively, you can also use Spring MVC . Here is an example ...

 // Below is in your view.java or presenter.java Window.open(GWT.getHostPageBaseURL() + "customer/order/balance.html?&orderId=99999", "_self", "enable"); // Below code in in your serverside controller.java @Controller @RequestMapping("/customer") public class ServletController { @RequestMapping(value = "/order/balance.html", method = RequestMethod.GET) public void downloadAuctionWonExcel(@RequestParam(value = "orderId", required = true) final String orderId, final HttpServletResponse res) throws Exception { try { System.out.println("Order Id is "+orderId); // more of your service codes } catch (Exception ex) { ex.printStackTrace(); } } } 
0
Jan 29 '14 at 9:23
source share

You can use Activities and Places . When you create a Place for your page, you can set orderId as a member. This member can be used afterwords when creating an Activity associated with a place (in an ActivityMapper ).

The only limitation is that you cannot send orderId as a regular parameter. You will need to use a URL with this form:

 127.0.0.1:60206/XUI.html?#TestPlace:orderId=1 
0
Apr 23 '14 at 13:52
source share



All Articles