Detect if page successfully rendered in Grails - javascript

I have a grails application where i have to detect if page is rendered successfully.
So, if I have render view: "mypage", I want to know if this page was rendered successfully by tomcat. Whether it reached user or not is not concern here. That is another part which can be tracked by using javascript events.
The solution that comes to my mind is using error controller and url mapping to map any issue like 404 or 500 to one controller but that controller is somewhat generic and will be handling multiple issues and not just this one.
So, Is it possible to exclusively know for this render call if it was rendered properly or not?

Try attaching a filter to the action with the afterView filter type. The documentation mentions that the first argument is an Exception, so if the first argument is null, then the render succeeded. (Also note that the documentation mentions afterView is called before the SiteMesh layout is applied, if that matters for this particular problem)

Related

Invalid Postback or Callback Error - How to find what is causing the error

I'm working on an asp.net web application and am running into this error after manipulating some controls client-side (html buttons nested in update panels):
"Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."
The stack trace given is:
"[ArgumentException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.]
System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId, String argument) +9832822
System.Web.UI.Control.ValidateEvent(String uniqueID, String eventArgument) +114
System.Web.UI.WebControls.DropDownList.LoadPostData(String postDataKey, NameValueCollection postCollection) +65
System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +18
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +471
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1897"
This stack trace is useless in that it's not telling me what control is causing the issue. I think I understand the basics of what the error is trying to say, but without a direction to go it's a total crapshoot as to where to start looking, particularly since I'm not manipulating any dropdown lists.
Before I go through the hassle of posting code, how can I get the complete stack trace (showing file and line number) for the error to figure out what is happening? I've been working on this problem for a week now and I'm pretty well fed up with it. Thanks.
hum, does this occur on a button click? Try moving any control validators to the top of the page, see if that helps. I guess a few more details as to "when" the error occurs. (does it occur on first page load, or due to some button click? And do you have any say JavaScript bits and parts that might have posted the page back before it is 100% rendered? I mean, something added to the page must have "started" this issue to occur. but, we quite much guessing. You could as a test in web config turn off page validation, and at least see if that works, and then try to fix and then re-enable.
Also, are you loading up data into some controls on page load?
Try then placing that "setup" and "data loading" inside of the !IsPostback (which all pages quite much need and have, right??).
So, in page load event, place that data load, and setup code you have inside of the !IsPostBack block like this:
if (!IsPostBack)
{
page load + setup + data loading code goes here
}
So, adopt the above if you have code to load up say a gridview, or even a dropdown box. I seen the above "simple" change in code fix your error, and a good number of times.

Equivalent of Request.RawUrl for Javascript

I apologize if this a duplicate question. I spent quite a while searching for a similar question but was not able to find one.
I am looking to get the URL of the current PartialView in java-script (in an angular controller). So far, methods I have found all return the existing browser URL:
window.href.location;
window.href.pathname;
as well as the $location service method in angular. However, I'm looking for a method that returns the same value as the Razor's '#Request.RawUrl' (i.e. the actual Route/URL of the PartialView).
For example, on page '/Category/{categoryId}/Product' I am showing a list of products. I am then using ngDialog and ngInclude to load a PartialView from '/Category/{categoryId}/Product/{productId}/[Whatever]' in a Dialog page.
Then I fire an angular controller in the PartialView. In that controller, I'd like to use the $http service and a URL relative to the PartialView's url. However, this is not possible, since angular is not aware of the PartialView's URL (i.e. the URL that #Request.RawUrl produces if used in the PartialView).
Thank you.
example

How can I redraw the ITHit Ajax File Browser in an Angular SPA when I've got all the instantiated parts?

For various reasons I will not go into, I have successfully wrapped the ITHit Ajax File browser inside of an Angular Controller, which itself is loaded and wrapped in an Angular-UI-Router UI-View.
All of the settings are configured through preceding service calls (to support a cloud environment with shifty urls), and I've even gotten through all of my CORS (Cross Origin Request) issues, and we've wired in a custom Oath2 implementation on the DAV server. All of this is successfully working with the ITHit File Browser as a pretty centerpiece for our content-browsing implementation.
As of now, when I navigate certain areas, the Angular-ui-router tweaks the Url, the view responds, and the Angular Controller wrapping ITHit responds to the view change, and (without reloading the view) re-fetches the appropriate DAV url with available IT Hit commands ( e.g. SetSelectedFolderAsync )
Here's my (hopefully simple) challenge: when I navigate to certain areas - Angular-UI-router simply reloads the containing UI-View with new content, but when I return - the ITHit Ajax File Browser does not redraw.
Here are some guidelines to my challenge (ignore-able if you offer something I can work with):
I'd prefer to avoid having to "hide" the ITHit container (because
it's irrelevant and I don't want to have to manage keeping it up to
date as state changes in the view. These changes affect DAV paths). Also I don't want to worry about unnecessary network traffic.
I'd really like to let Angular-UI-Router do its thing with the
ui-view in which the browser is resting.
I'd like to keep
whatever calls need to be made invokable to the Angular Controller
(it's managing authentication, path resolution, and contextual
settings config - which change as users navigate).
Everything (well most important things) generated by the ITHit solution is
stored in a Singleton ('DavBrowserService') - so when I return to
the file-browser view, I have everything stored from the initial
instantiation including:
an instance of ITHit Object
the produced instance of the ITHit.Loader
an instance of the previously produced AjaxFileBrowser.Controller Object (ITHit.oNS.Controller)
an instance of the previously produced WebDavSession Object ( ITHit.oNS.WebDavSession)
With the above in place - I'm hoping that I can simply re-wire these instances back on to the now-returned dom-node ('afb-content-div').
Any help is MUCH appreciated!
UPDATE: The below "answer" while appearing to be functional - indeed was NOT. However, I have worked around this issue by grabbing the DOM instance and storing it memory when the user navigates away, and re-attaching it after the user has navigated back to the appropriate area. This way all of the ITHit Magic is still tied to the right DOM node, and I don't have to worry about the partial re-instantiation weirdness. Seems to be pretty solid now.
I figured it out!!! It looks like if I re-instantiate the controller by calling:
var controllerInstance = new ITHit.oNS.Controller( originalSettingsObj );
Everything rewires magically! I've wrapped the above code with some detection for whether the 'afb-content-div' HTML DOM node has children.
After much digging in the code, it looks like this is the argument object returned to as a parameter to ITHitLoader.oninit callback (From the AjaxFileBrowserLoader instance).
Thanks for playing!

Backbone.js Session Implementation Flow

I have a simple OAuth verification set up using Backbone, and it's working fairly well. My question is somewhat nitpicky (though... I am also new to Backbone), but I'm hoping to find somebody who might know how to solve this.
I have a Session model which, at initialization, sets a #authenticated value based on the presence of a value in localStorage. There's also a method in here, authenticate(), which checks the #authenticated value for pass/fail. If the value check fails, it uses my router to navigate to the login route. If the value check passes, an optional callback passed in by the user is run.
In my main AppView (the first View run at application start) I run Session.authenticate(), and if it passes, route to "#home" (and my Router handles loading additional Views).
My question is this: as an un-authenticated user, if I type http://url.com/#home into my browser, I am successfully routed to "#login", but if I bring up my DevTools, I can see a request being made for an image in my "HomeView" view. What am I not understanding about how Backbone flows through this process? Shouldn't the route for "#home" not even run until after the application initializes, and therefore not even attempting to load the "HomeView"?
What kind of templating engine are you using? If your templates are for instance inline, inside the HTML template where your backbone app lives, then I believe any images inside those are rendered when the page loads. I may be wrong. Also, ensure your HomeView is not running by logging something to the console in the view's initialize method.

FullCalendar: Fetching the initial date/time-stamp to show once events are fetched from server

First of all, hats off to Adam for pulling off this wonderful, well-written calendar plugin!
Now for a a very typical use case. Below is what I want to achieve:
Fetch events (URL added to eventSources) from the server side as JSON data. This is all fine and I have been able to achieve this. The events get rendered properly.
USE CASE in question: Once the fetch is completed and BEFORE the events are rendered and shown on the browser, I want to 'fetch' the initial month/date to show to the end user. I was thinking of a separate AJAX request to fetch the timing details from the server side and then use 'gotoDate' to switch the view's date.
The reason for this specific requirement, being that that the end user would like to see all the events and initial view w.r.t the server time. In our application it is possible that the client and the server box are not at all sync'd w.r.t time.
Unfortunately, as yet I am not able to locate any callback method that gets invoked once the event fetch (all relevant events) is complete and 'before' the events get rendered on the view.
Any help here will be appreciated. Please let me know if any further info is required.
Thanks,
Mohit
"events" - can process a single event source, this could be an array / JSON feed or function.
"eventSources" - is similar except that it expects multiple event sources, these can also be an array of arrays/functions/JSON feeds (anything that the events option would take).
To process the data before it is rendered I expect you could use a function to do some post processing after you have fetched your data with an AJAX request. See e.g.:
http://arshaw.com/fullcalendar/docs/event_data/events_function/

Categories

Resources