Using Extjs4 in the frontend - model-view-controller

I've been a big fan of BackboneJS (and still am) until I discover Extjs4 in my new Job. I can only tip my hat for what it can do! Now my question is whether it is possible (or recommanded) to use Extjs in the frontOffice without using its components. I only want to take advantage of both the MVC architecture that it offers and the module loader feature. With backbone, I use AMD and require Js for module loading and it's a pain and very hard to generate production build.
I'm wondering also if Extjs will have a JavaScript routing engine in the next version.
Your advice will be very appreciated,
Thank You.

Sound great that you are BackboneJS fan. To answer your question... You can use ExtJS anywhere in web application which makes end-user an real cutting-edge tech. You already worked in Backbone and learning ExtJS. First consider which one you need to use for your application, either BackboneJS or ExtJS, because both are advance concept of JS.
For your second question, ExtJS use well structured MVC pattern over BackboneJS. You dont need to migrate to ExtJS if you can able to create custom Controller(Getting components reference) control in BackboneJS. My suggestion is to go with ExtJS.
ExtJS sencha forum is really good one to learn more over their component reference and raise bugs and request for any new javascript routing engine as you mentioned.

Related

Calling a Component from Ajax in CakePHP

I've been developing a web application in CakePHP 2.x that uses an Image cropping tool to manipulate an image. Currently it passes Ajax calls to handle the manipulation onto a function within the current Controller which then calls a Component which contains the main processing and functionality.
I'm currently going through and refactoring this section of the code and I was wondering if it's possible to directly call the Component from Ajax and whether or not it is a good idea or not as it would simplify a chunk of the code if possible.
Thoughts, opinions and tips are greatly appreciated. Thanks :)
I'm currently going through and refactoring this section of the code and I was wondering if it's possible to directly call the Component from Ajax and whether or not it is a good idea or not as it would simplify a chunk of the code if possible.
It's not a good idea because this is how components are thought to be used. A component is not thought to receive a request directly but to provide additional - reuseable functionality - to the controlller level in the MVC pattern.
Taken from the documentation:
Components are packages of logic that are shared between controllers. CakePHP comes with a fantastic set of core components you can use to aid in various common tasks. You can also create your own components. If you find yourself wanting to copy and paste things between controllers, you should consider creating your own component to contain the functionality. Creating components keeps controller code clean and allows you to reuse code between projects.

SPA using DurandalJS and laravel

im trying to create a Single Page Website with DurandalJS in the frontend and Laravel as the Backend. Do you think this is a good Idea?
If yes how would I do the following:
What would your recommendation for the basic interaction between both frameworks be?
Would you rather have all the computation done in JS instead of Laravel sending calculated and styled returns?
How Do I setup Laravels controller in order to only get dynamic Data for, say a Div, instead of a whole page?
How can I adjust the browser URLs?
I hope I was specific enough, thank You in advance.
Laravel does not actually care about what framework you use to build the Frontend. Laravel is just a framework that helps you build your application with. It gives you great advantage with respect to the time spent and effort.
You can use any frontend framework that you want to build your app with. I have actually not used Durandal, but from the first look of it here is my opinion.
Durandal is built on top of jQuery, knockoutJS and requireJS. It also has a MV* architecture in place with support for eventing as well. So you could basically define routes on Laravel and initiate the communication between both the frameworks through events and ajax. Again this completely depends on the functionality that you are building.
In the overall flow of your app, consider Laravel as a Model that just gives data from a source to your app and Durandal as your views and controllers. This way, it will keep your data flow cleaner and easier to build. Computation of your functionality depends on how important and secretive the app is. If there are functionalities/implementations that you need to be secretive about, you can keep it on Laravel and just send computed data to Durandal. If its a web app that you are building, then keeping all implementation on the JS is just a right click away from knowing what and how you have built it. One can just see how the implementation is done just looking at the Javascript source of the web app. If you are building Mobile Device App, then the case is different.
Take a look at Restful Controllers. Will give you an idea on how to setup controllers to return only data. But if you need to return the div itself, then you can make use of the Basic Controllers of Laravel to perform them.
You can setup cleaner routes for the browser URL's. Take a look at Laravel Routing

Front End Frameworks for RESTful backend

I am developing a RESTful backend using Spring framework. All the services are accessible through HTTP request methods (GET, POST, PUT, DELETE).
Could you please tell me what can the best combination of frameworks for front end?
Is it best to use SpringMVC or some other framework like Backbone is good enough?
If I am using SpringMVC for REST backend and also SpringMVC for front end then won't it be extra work doing same things again first for backend then for front end?
And most important I am confused about how can do the session management using front end?
Any help will be appreciated!
If you are looking into to make a SPA (Single Page App) make sure that you take a look at AmpersandJS -> http://ampersandjs.com/
Templates
Since you said "server-side" GUI, maybe you are thinking more along the lines of a template engine for creating HTML? This isn't really restful, but can be MVC like if you are forwarding from your Controller classes.
But PLEASE keep in mind that it would be a very BAD idea to try and generate XML or JSON data for consumption by RESTful clients (ajax) with either of these. Just say no to JSON creation from a template engine!
JSP is pretty much the standard for Java EE at the moment, or is most widely used. All you need is a compliant server, such as Tomcat/Jetty.
http://www.oracle.com/technetwork/java/javaee/jsp/index.html
Thymeleaf It looks a lot cleaner than JSP, and has the added benefit of not allowing all the pitfalls that can happen with a JSP (and there are a lot).
http://www.thymeleaf.org/
JavaScript:
When you say you are creating a RESTful backend, most people would make the conclusion (and rightfully so) that you are trying to develop a JavaScript MVVM client/GUI.
Kendo UI has a complete set of GUI widgets and MVVM framework that is specifically designed to work with a RESTful backend. But it's a paid for API.
http://www.telerik.com/kendo-ui
YUI3 (Yahoo User Interface) has a variety of widgets as well, and I've seen a lot of jobs requesting this. It has the advantage of being free/OSS as well. Older version are deprecated.
https://github.com/yui/yui3/wiki
knockout.js has been my favorite for MVVM engines that I've actually had experience working with. And it's simple to learn, in my opinion.
http://knockoutjs.com/
Angular.js Also free/oss, and works well with other GUI APIs.
https://angularjs.org/
I would suggest you to consioder Sencha Ext JS for front-end, it is one of the best framework and will work with RestFul back-end.
this is a good question, but I don't think there is a server-side framework out there specifically built to use a REST server backend. I think you could use Spring-MVC / Spring-Boot to get a good headstart, but you might also want to look into Rails or other Ruby any other modern web framework technology.

most commonly used AJAX library with Struts 2?

I need to integrate AJAX functionality into a Struts 2 web application. I was looking at some tutorials and was going to try using the Dojo Plugin but quickly realized it has been deprecated as of Struts 2.1.
The AJAX documentation for Struts 2 gives a lot of potential solutions and I'm trying to narrow it down a little.
I realize this question is a little general and there are some existing Questions here about specific alternatives, but I'd like to get a feel from the community as to what is the most commonly used approach.
I'm also interested in whether it is more common to use one of the AJAX taglib plugins (ie. struts2-jquery) or straight AJAX widgets independent of Struts.
I understand the basic concepts of AJAX but don't have much hands-on experience with any of the libraries. I don't mind putting in some time getting up to speed on something if necessary.
Thanks much for any suggestions!
I'd recommend doing it manually via some JS library and them moving to a taglib plugin once you understand exactly what the plugin is abstracting away for you. I think that getting that hands-on experience with the libraries is a better educational / training investment. That way when you move on to another web framework you'll have a better understanding of the javascript API side of things.
jQuery is probably your best choice so you could move on to the struts2-jquery plugin if you decide it's worth it. The Struts 2 jQuery plugin is actively maintained (albeit a few versions behind on jquery/jquery-ui) and I have friends that are using it quite happily. Still, I personally tend to stick with direct jQuery ajax calls to Struts 2 actions that return JSON or FreeMarker snippets for autocompletion, updating search results, etc.
Use whatever JS framework(s) you want to and don't bother with a plugin unless it offers you a compelling reason to use it.
If you haven't used a JS framework before and are looking for suggestions, I'd recommend jQuery.

Is AJAX easier with ZendX_JQuery or with Zend_Dojo?

The context is that I don't want to use Zend MVC - controllers, helpers, decorators etc - that's overkill for what I am writing.
I've scoured the jQuery site plugins section and these issues bother me most:
I have to search a lot for plugins - it is tedious.
I have to check dependencies with jQuery versions. Thankfully I decided to stick with only jQuery or noConflict() would have driven me crazy.
I have to hook-up all the id's and names of form elements across HTML+CSS+JQuery through Controllers, Views etc.
And all this because there is no other simpler PHP wrapper over jQuery plugins than ZendX_JQuery - and plugins is where the attractive scripts and effects are.
Writing a in-house replacement to ZendX_JQuery will be a huge task in itself. But if you have to wrap third party jQuery plugins in PHP and maintain the thing it is full time job in itself.
So I want to know if Zend_Dojo is much easier than ZendX_JQuery. I'm asking before trying out because I'd have to spend a couple more days installing, configuring and testing all the standard Dojo controls and then I can decide. All that's tedious for a rather simple app which may grow later on.
The alternative would be a "jQuery-inside" PHP widget library that is stable and will work for a year without being broken or upgraded.
Something like GWT or ZK or ASP.Net where you don't have to do low-level HTML+jQuery coding and hand-tweaking for every page with all the ajax controls and form elements.
Or should I just drop an MVC framework altogether and replace it with a custom set of scripts only using Zend components where necessary - like Zend_Validate, Zend_Form etc.
I've been working on desktop apps for some time and the switch to AJAX + MVC + Zend is proving a bit too unwieldy, especially given the abundance of design patterns in Zend MVC.
My recommendation would be to use neither ZendX_JQuery or Zend_Dojo. By the sounds of it, that's overkill for you as well. My thoughts may be coloured by the fact that I don't like to mix PHP and JavaScript code except where absolutely necessary - yes, it may be easier to let a component write your JavaScript for you, but it's never going to be as clean as you could write it yourself.
That way, you also maintain separation between behaviour and presentation - always a good thing, as it makes it easier to use the concepts of progressive enhancement.
I agree with Stephen Orr- I use neither jquery nor dojo (after trying both). I use Zend_Form filters / decorators heavily because client side validation has to be redone on the server side anyway. With some custom decorators, you can do it all in html/php.
I try and avoid ajax where possible, and use prototype / scriptaculous where it cannot be avoided. They are lightweight and provide handy shortcuts to use in other JS code.

Resources