3
votes

I have a Java/GWT application. In that there is a list of items. If I click on any item title then that item is opened with full description.

I am using Anchor for the item title, so what I want is when user clicks on item title then in the URL the id of that item is appended to the current URL.

For example, this is my URL:

"http://127.0.0.1:8888/MyApp.html?gwt.codesvr=127.0.0.1:9997#listItem?list"

and I have to append id to the end of the URL like:

"http://127.0.0.1:8888/MyApp.html?gwt.codesvr=127.0.0.1:9997#listItem?list&itemId=55"
5
You should probably use com.google.gwt.user.client.History, and replace your Anchor with an Hyperlink. - Thomas Broyer

5 Answers

2
votes

Using Window.Location should do your trick : see the doc here

Something like this :

String url = Window.Location.getHref();
url = url + "&itemId=" + itemId;
Window.Location.replace(url);

Although of course, as Crollster pointed out, you should insert your url parameter before the # sign. Give more details on what you're looking for exactly (why do you have to add the parameter manually, does the page have to reload ...)

1
votes

you can use redirect command in order to add this parameter

response.sendRedirect(your url + itemId=55);

Then you can extract this variable.

I hope this will help.

0
votes

You can try with javascript coding.When the user clicks on link, get this URL and appends your id to it and reconstruct the URL.

0
votes

You see that # in the URL? Thats an anchor - you will need your parameter to be added before that, so it looks like this:

http://127.0.0.1:8888/MyApp.html?gwt.codesvr=127.0.0.1:9997&itemId=55#listItem?list

HTH

-2
votes

URIBuilder of Apache HttpComponents offers a convenient method to add parameters and will deal with existing query parameters and anchors.