I am starting with jqtree and I need to load data from server, without url (I have seen examples of loading ajax data from url, and it's not what I need) and I haven't found anything about that anywhere. Does someone know how can I set a jqtree treeview calling the data from the server? Also, how should I return the json node list?
A server request needs a URL. That's how HTTP works.
An alternative you can try is to put the data directly into the page which initializes the jqtree. The data attribute can directly be given a JS object.
Related
Is there any way to get CRX content without using OSGI service?
Am looking for an use case to implement a top navigation for a website which is required to read page names and its properties via javascript framework like angular JS.
You could get it as JSON or XML, make a server call to path with extension XML or JSON. JSON allows you depth based selectors to go down the tree hierarchy not sure if its same with XML.
/my/page/path.xml or /my/page/path.<depth>.json, you can get the hostname and port details from the request URI to make the complete URL for the data call.
I would suggest you use the following JSON API's provided by sling to accomplish your task of getting page names and its properties.
Firstly to crawl all the pages under a given path, you need to use the .pages.json selector. For example to get all child pages of /content/company/en_US, perform a JSON GET on
HTTP GET <Host>/content/company/en_US.pages.json
Next for each path returned by the above GET call, you need to grab the _jcr_content.json of the page
(E.g.)
HTTP GET <Host>/content/company/en_US/home/_jcr_content.json
The above JSON call should provide you all the page properties of this particular page.
Please Note: The above method is generic and can be applied to any JCR Path hosted in Sling/AEM. Also typically you cannot get this level of JCR access in a publisher environment due to security rules that might prevent JCR crawling. Hope this helps
I have 3 JSP views which all use the same JS file(say app.js).
My UI is on AngularJS which has a different controller for each of the JSP views and also has a custom service which shares information between the controllers. When I load the first JSP, its controller specified in the app.js file saves a value in the custom service. When I load the next JSP file, app.js gets reloaded and so the value that was saved in the custom service is lost.
Is there a way to not re-load JS files? Or is there a better way to go about this?
If you have no control on the server , you can save the data in browser's session storage object to keep data across requests and clean it, when you are done. https://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage
// Save data to sessionStorage
sessionStorage.setItem('key', 'value');
// Get saved data from sessionStorage
var data = sessionStorage.getItem('key');
// Remove saved data from sessionStorage
sessionStorage.removeItem('key')
Javascript variable are not automatically preserved. When you open a new URL in your browser, you do not download again the JS files (they are cached), but they are loaded from scratch in that new page. That means that all previous values are lost, not by accident but by design.
You have different ways to deal with this persistence between page question. One way is server side by using the session:
the js part sends the value to save as parameters of a request
a spring-mvc controller puts that in the session
other views (jsp) or controllers (spring) access the saved value and pass it in the responses
An alternate way is the single page application pattern:
you only load one single full page from the server
the javascript then only sends requests that it processes directly to modify the DOM
Additionally, you could use Windows.sessionStorage to store data client side for the duration of a client session - credits should go to #AmitParashar for this one, more details in his answer.
You can of course mix the 2 patterns (this is commonly done in real world applications), but you must know that every page load will erase all client javascript state
A less common pattern (AFAIK) is to put the state in a cookie. That way it can be shared by the server and the client but:
it is limited to 4k size
you cannot use it for server side security, because it can too easily be forged
So I have this code to access data from JSON file.
taskAppControllers.controller('MainMenuCtrl', ['$scope','$http',
function($scope, $http){
$http.get('data/main-menu.json').success(function(data){
$scope.mainMenuOptions = data
});
}]);
Everything is fine. But when I change JSON files, everything stays as it was. If I rename JSON file and access it, it will show updated data, and if afterwards, I rename it back, it will display the output from JSON before it was edited. It probably saves data in browser memory or something similar. It's cache related issue. How do I fix/reset it?
Sound like caching issue, try appending random parameter to the URL, to force fetching a fresh copy from the server:
$http.get('data/main-menu.json?' + Math.random())
I don't believe that this is actually an angular-specific issue. Your browser would likely cache this.
If main-menu.json should be static, consider just doing ctrl+F5 instead of F5 during your debug sessions. If it needs to be updated, you could either change your caching-related response headers to let the browser know that it should not cache, or you could add a "cache buster" to the request by adding a timestamp as a request parameter. That's not the preferred way to handle it, though.
Assuming i understand you correctly, Angular will not dynamically update in the way you're expecting. It will only update when you reload the page or if you code it to reload the data from the server I.e recall the $http service.
You'll probably want to poll the server to check if the data changes or use something like SignalR to "push" the new data to the browser.
i had been working in a Spring Rest Data API in an application (just for fun).
I have the core made, works fine but now I want to use AngularJS as front-end.
I had work with Jackson (Mapping Java Objects to JSON), but with Spring Rest Data the Json response it's diferent, it has _embedded, _links, self, etc. links that make me confuse. I have something like this in the root url http://localhost/8080/app/api/tarifas
I have used a JS script called restangular but i have serveral problems (I'm newbie with Angular)
In my controller i have this
Check the error
If I add a RestangularProvider in my app.config(...) and change the Controller to getList instead get, works fine, but I need several entities data formats.
Any help it's welcome. If you know a better way please tell me.
Thanks!!
UPDATE
I found a form to do this (i donĀ“t know if it's the better) but now my problem is the next:
I have objects that has other objects as attributes (realtionship), and the reference in the JSON is a link (not an object). Then, in the grid; the value of the description's internal object is blank. To get the json data I found this
Now I have the next content for one register (one of the grid)
And my grid (In Angular, HTML) looks like this (empty fields)
How can I retrieve the attribute description from the member estado, categoria, etc. and show it in the grid. Should make the request to get it?
Thanks!!
You can use either angular.toJson or json.stringify
Angular-toJson documentation
Json.stringify documentation
I have created RESTFUL urls that respond with some JSON data when fetched by backbone.
So a url like /lists responds with a json array of user-created lists. My want that if the url is accessed by address bar input like mydomain.com/lists, the json data is displayed in text on browser. I want the server to respond only if the url is accessed from within the application. Can somebody provide me some hints on how to achieve this?
Like #Thilo said, you're not going to be able to do prevent a person with the right tools to see what's coming across the wire, Firebug's console/net tabs already keep track of requests and show the contents of responses.
That being said, what you can do is check whether the HTTP_X_REQUESTED_WITH HTTP header is set to 'XMLHttpRequest', and only return the JSON in this case. Backbone makes an Ajax call so this will always be the case with the Backbone calls (in modern browsers). Again this won't help much except for people who type it into the address bar directly (and do a normal GET request) won't see the JSON.