Updating URL without refresh - gwt

I am iterating through data and generating parameterized URL's for links (to the same page, but with parameters) on a dashboard app. However, the way I'm doing it requires a page refresh when the user clicks the link.
Generating URL with a StringBuilder
Detailhtml.append("<a href=\"http://" + domain + "&service=" + count +"&day=" + day +"\"><img src=\"/info.jpg\" alt=\"Info\"/>");
Is there a way I can dynamically create GWT buttons, or trigger some javascript to add the parameters without a page refresh?
Any help would be great...

The page will refresh if any part of the URL before the fragment (#) changes. So if you go form foo.com#a to foo.com/?bar=baz#a, a page refresh will be triggered.
The best way to get around this is just to never change anything before the fragment. Change foo.com/?bar=baz to foo.com/#bar=baz (or some variant) and have your GWT app listen for History changes by calling History.addHistoryListener(...).
Then, when you hear a history change, parse the fragment in the URL and update your app accordingly.
Some libraries like gwt-platform provide a wrapper around this functionality and let you describe Places which will get triggered when the fragment updates to match them. If you end up doing a lot of complicated things with the fragment, it would be a good idea to look into places. But if you're just passing a few parameters around, you can get away with just listening for History changes.

Related

Redirect in Sharepoint 2010 Event Receiver

I'm looking at some code which has broken the saving of changes of a List item in SP2010. In the constructor of the Event Receiver the HttpContext is being stored as a local variable then in the ItemUpdating at the end a query parameter containing the return url is retrieved and passed the SPUtility.Redirect(...). This has the effect of canceling any changes that were made in the edit form. So following so scenarios I've found online I'm storing the HttpContext as a static class object and redirecting in the ItemUpdated event and edits are now persisted followed by a redirect to where we are expecting.
I have a concern though with storing a specific user's HttpContext as a static on a class which will potentially be hijacked if another user does the same action between the time user 1 sets the context initially and prior to the redirect. User 2 will overwrite the context and there are potential issues.
The only other option I can think of as a quick way out would be to store a static Dictionary where the key is the user id then remove the entry just prior to redirecting so as to not leave stray HttpContext instances leaking.
So looking at the accepted solution from here the first response by servy42 states The fact that it works for a few trivial test cases at first doesn't make it a viable solution. but doesn't suggest a viable solution.
There's another option best approach may be changing Save Button in ribbon such that when clicked, a ECMA script first save your Item, then redirect to other page, or open other page in dialog. suggested further down but is that the only other way to go?
I'm fairly new to SP and just trying to navigate through the wealth of wrong ways of doing things with my limited knowledge, whilst unfortunately being stuck with SP2010.
Any thoughts on how to go about this?
============
Edit: Further info as requested
So there are two sites one say called A which will have a sub site called B. A has a List and adding an item to that list triggers event receivers which creates sub site B and other related stuff. If I modify the B "item" from the SharePoint list of Bs then I don't need to redirect and returning to the list is fine. If I'm looking and a neatly rendered Gantt chart on A listing the Bs the if I edit B after clicking Save we need to come back to A. If I'm on B there's an edit button as well so I want to return to B after editing and clicking save.
So we have the source= appended when we go to the edit screen. From some reading I've done it seems SharePoint will pick that up and redirect. One of the fields on the edit page is the relative url beneath the A site and if that changes then the redirect url will no longer be valid and throw a 404 so we replace the old B sub path with the newly entered value. But we then need code to redirect to the new location.
I am not quite sure whether i understand your requirements correctly. But i will give it a try. Just a quick summary of what i understood (correct me if i am wrong...):
You have a Root Web in a site collection with a list
Each entry in that list corresponds to a subsite which will be created on List Item creation (ER) below the Root Web as a subsite
List items can be edited from both the List in the root web as well as from the subsite it maps to
On editing from the subsite you want to return to the subsite after saving
My approach would be this:
Follow the steps described in this article SP Dialog and List Forms
Open a dialog on the subsite that links to the edit form of the root web.
After saving the user finds himself already where he should be
Hope this helps... Cheers!
Edit: Just read the requirement about changing of url. Create a custom Edit Form which you enhance with some js that passes values back to the origin site -> Parameters in dialogs. You may then react accordingly in the javascript callback and redirect to the new url.

displaying own like count next to like button

I have a website where the URLs have some tracking parameters that do not affect the page that is displayed i.e. the URL is of the form http://mywebsite.com/page1?tracking1=aaa&tracking2=bbb and 'tracking1' and 'tracking2' are just tracking parameters used for some other purpose and do no determine the page that is displayed. The page that is displayed is always 'http://mywebsite.com/page1' irrespective of the values of these tracking parameters.
I have included the facebook like button on my website pages and facebook treats each of these URLs, including the tracking parameters, as separate pages. I'm not able to get facebook to ignore these tracking parameters and just consider the URL without tracking parameters as a page. So, I'm storing my own like count against the actual URL (when I get a callback on the like action) and displaying it next to the like button.
Is displaying own like count next to facebook like button against their usage policy? Is there a better way to do this?
Is there any particular functional reason you're using GET (ie URL) variables to store your tracking?
If you can push them into POST instead, or use cookies or sessions for your tracking, you can simplify your URLs and Facebook should treat it as a single page.
If you have to use GET due to, for example, the links coming from external websites, you could use a pass-through URL to do your tracking, before forwarding to the main page. ie someone clicks the link to redirect?tracking1=aaa&tracking2=bbb&page=page1
And redirect, as you may have guessed, does what you need to do with your tracking before forwarding the user on to page1.

Refresh Fb Comments Plugin

I'm trying to add a link to allow a user to refresh the Comments plugin on my page so they can see other posts by other people.
I want to do it without refreshing the full page.
There's a html5 player on the page playing audio, hence me not wanting to interrupt that player.
Currently I'm using the standard -
I've tried the jQuery method of giving the div an id and having a header script which counts to 10 and reloads the div widget, it seems to reload the widget, but it doesn't update the contents of the comments plugin to show other's posts, just ones you've added yourself. To see all the updates you have to refresh the page fully, which I don't want to do.
I'm trying to avoid iFrames because of the height issues and extra scroll bars, etc.
Any ideas would be appreciated
I'm not exactly sure what you're trying to do, but you can use the FB.XFBML.parse method to refresh plugins.
The only thing is that you'll need to first remove the old plugin from the dom, then add the new html5/xfbml placeholders (what you get from the comments plugin page when clicking "get code") and then use the FB.XFBML.parse method.

History management (Refresh Button)

Please give me idea about the management of data in GWT. I am using Gwt in my travel portal project and my web pages is related to previous page data but when i press the refresh button of browser's then my data is lost . so please inform me if there is any way to manage this problem.
GWT History class cannot be used to manage page refresh (only back/forward).
A click on the refresh button send a request to the server and the state of the application is reloaded from the server. That's all. You have to deal with it.
If you don't want to lose your data, you have to find a way to save it on the server when it's needed.
If your users have modern browsers, you can use the HTML5 feature localStorage to store the data in the browser between page-refresh.
Check this thread for supported browser.
You can create a url fragment to encode your data.
String location = "ny";
History.newItem("location="+location);
will result with a url fragment of www.example.com#location=ny
Then if the browser is refreshed, you can decode the url fragment and determine that the location is ny.
For multiple parameters you can create a complex fragment and parse it.
History.newItem("start="+startLocation+"&end="+endLocation);
Then the url would look like www.example.com#start=newyork&end=boston
The basic idea is to store some state in the URL fragment (the part of the URL after the #) -- for example your-site.com/app#page-1
To listen for changes to the fragment, use GWT's History class. The fragment will change when the user goes back/forward, or refreshes the page.
So you could have your app do different things when the URL has #page-1 vs #page-2, etc.
A more generalized and scalable solution to this is something like gwt-platform's Place architecture (along with Presenters, which are also a good idea for large apps)

Trigger HTML POST/Form submit w/o JavaScript

I have a timed page that I need to use to submit a form upon the end of a specified time period.
The usage would be: User visits page, 90 seconds later all form data is submitted and user is redirected to next page.
The user is well aware that the page they are on is timed (its for a web-only experiment), so I'm not worried about "unfriendly" browser behavior on this page.
Ideally, I'd like to avoid using JavaScript (some of our targeted users are using no-script for various reasons, but if its the only way, so be it), and would also like to avoid just passing variables through the URL (to cut down on the possibility of spoofing). It is easy enough to set a META refresh tag to do the redirecting, but at the end of the time period I need some way for the response header to be set as if the submit button was clicked, whether or not it actually was.
Thanks in advance for any thoughts you might have.
Can't be done.