Ext JS in Action, 2nd Edition - Ebook download as PDF File .pdf), Text File .txt) or read book online. Ext JS in Action, 2nd Edition. Contribute to ckjdelhi/Oracle-ADF development by creating an account on GitHub . No part of this book may be reproduced, stored in a retrieval system, or transmitted ISBN mmoonneeyy.infoub. active community member for the modern yui-ext library—Ext JS. Shea's expertise . Buttons and form action.
|Language:||English, Spanish, Arabic|
|ePub File Size:||15.58 MB|
|PDF File Size:||15.75 MB|
|Distribution:||Free* [*Regsitration Required]|
January ; ISBN ; pages; printed in black & white An eBook copy of the previous edition, Ext JS in Action (First Edition), is included at. For this book, we won't focus . extensively throughout this book, and we want to make sure you have at least a Figure shows the Ext JS grid panel in action. .. To download their free eBook in PDF, ePub, and Kindle formats, owners. Ext JS in Action, Second Edition This book was set in /12pt Adobe Garamond by Laserwords Private Limited and printed Entrepreneurship, Second .
If any are found, itll attempt to create an instance of that component using ComponentManager. If the renderTo or applyTo parameter is passed into the constructor, the render phase begins at this time; otherwise, the component lies dormant, awaiting its render method to be called either by your code or by a parent component. Naturally, the range of solutions available is quite large. No way. The data package has seen a lot of attention, but the layout namespace has seen a lot of refactoring love as well. Amazon Rapids Fun stories for kids on the go.
Contains the entire framework, in minified and concatenated chunks to allow for browser consumption over slower connections. Its broken up into foundation, DOM, classes, and extras.
Know that anything with -debug in the name is a nonminified version of that file. These can be broken down into two groups. First are ext. These two contain the foundation of the framework. Include these when you want to use the Ext JS class loader. Youll use ext-all-debug for the exercises.
Although there are quite a few files and folders in the distribution, you need only a few of them to get the framework running in your browser.
Now is a good time to look at using Ext JS for the first time. Take it for a test drive For this exercise youre going to create an instance of Ext. Panel, which will be rendered inside an Ext. The form panel will contain two text input fields and a button to provide some feedback once clicked. The following listing demonstrates how youll bootstrap the application code. Listing 1. Be sure to change it if your path is different.
The first, shown in the next listing, is the construction of the form panel and its related child components. First, you create an instance of Ext. Template B, which youll use later to create a dynamic dialog text body.
Next, you create an instance of Ext. FormPanel c, which contains two text input fields d and a button e. The button is configured with a handler that uses the template you configured earlier and values from the form panel to display an Ext.
Msg alert dialog f.
Youre almost done with the Hello world example. Your form hasnt been rendered onscreen yet. For this, you need to call Ext.
Youll also wrap the form panel inside the window to demonstrate the flexibility of the framework in the next listing. You first call Ext. Inside this anonymous function is where you create your Ext.
Window instance c, which contains your FormPanel instance d. To exercise the Submit button handler you need to enter data in the two input fields and click the Submit button. If youve done everything correctly, you should see the Ext.
Msg alert dialog using the data that you placed in the form. There you have it! Though this example was simple in nature, it shows you the power of Ext JS. Summary In this introduction to Ext JS, you learned how it can be used to build robust web applications. You also learned how it measures up against other popular frameworks. You explored many of the core UI widgets that the framework provides and learned that the many prebuilt widgets help rapid application development efforts.
We also investigated some of the changes that Ext JS 4. Finally, you saw how to download and set up the framework with each base framework. You created a Hello world example of how to use an Ext JS window to render a form panel with a button that displays an Ext.
Then well discuss using Ext. Element to manipulate the DOM. As you know, DOM manipulation is one of the tasks that web developers are required to code for most of the time. Whether its the addition or removal of elements, Im sure youve felt the pain of performing these tasks with the out-of-the-box.
Youll learn to use Ext. Element to add nodes to and remove them from the DOM, and youll see how it makes this task easier. Once youre familiar with the Ext.
For Web 2. Heres where you can achieve the right balance of timing and performance. We like to call this the sweet spot in the page-loading cycle. Like many things in the world of browser development, each browser generally has its own way of knowing when its DOM nodes can be manipulated. Native browser solutions are available for detecting that the DOM is ready, but they arent implemented uniformly across each browser.
Internet Explorer requires a script tag to be placed in the document with a defer attribute, which fires when its DOM is ready. WebKit fires no event but sets the document. Boy, what a mess! Luckily, you have Ext.
In the preceding example, you pass whats known as an anonymous function to Ext. Your anonymous function contains a line of code to invoke an Ext JS MessageBox, as shown in figure 2.
An anonymous function is any function that has no variable reference to it or key reference in an object. In short, an event is like a message that something has occurred. A listener is a method thats registered to be executed, or called, when that event occurs, or fires. Ext JS fires this docReadyEvent event when it finds exactly the right time remember the sweet spot in the page-loading cycle to execute your anonymous method and any other registered listeners.
If the concept of events sounds a bit confusing, dont be alarmed. Event management is a complex topic, and well cover it later in chapter 3.
We cant stress enough the importance of using Ext. All of the example code has to be launched this way. Moving forward, if Ext. Some code here Now that youre comfortable with using Ext.
Element class. This is essential knowledge thats used everywhere in the framework where DOM manipulation occurs. Managing DOM elements with Ext.
But what if you want to do more with the node, such as manage its events, apply a style on mouse click, or replace a single CSS class? Youll have to manage all of your own code and constantly update to make sure your code is fully cross-browser compatible. We cant think of another thing that wed want to spend less time on. Thankfully, Ext JS takes care of this for you. The heart of the framework Lets turn to the Ext. Element class, which is known to many in the Ext JS community as the heart of the framework because it plays a role in every UI widget and can be generally accessed by the getEl method or the el property.
The Ext. Element class is a full DOM element-management suite, which includes a treasure chest of utilities, enabling the framework to work its magic on the DOM and provide the robust UI that weve come to enjoy. This toolset and all of its power are available to you, the end developer. Because of its design, its capabilities arent relegated to simple management of DOM elements but to performing complex tasks such as managing dimensions, alignments, and coordinates with relative ease.
You can also easily update an element via Ajax, manage child nodes, animate, enjoy full event management, and much more. Using Ext. Element for the first time Using Ext. Element is easy and makes some of the hardest tasks simple. To take advantage of Ext. Element, you need to set up a base page. With this code, youre setting the stage for this books examples by ensuring your target div tags have specific dimensions and a border so you can clearly see them on the page.
You include one div with the id of 'div1', which youll use as a target. If you set up your page correctly, the stylized div should be clearly visible, as shown in figure 2. Element methods. Element example code will reference the base page you just set up. If youre interested in watching changes to the DOM occur live, we suggest using the multiline Firebug text editor in Firefox with these examples.
If youre unfamiliar with Firebug, you can learn about it at http: Or you can place these examples inside generic script blocks. Just be sure to use Ext. According to the CSS, any div with the class myDiv is set to 35 pixels high and pixels wide and looks a bit odd. Lets make that element perfectly square by setting the height to pixels: The execution of the previous two lines is pretty important.
The first line uses Ext. Element referenced by the variable myDiv1. Use your newly referenced instance of Ext. Element, myDiv1, and call its setHeight method, passing it an integer value of , which grows the box to pixels tall.
Alternatively, you could use its setWidth method to change the width of the element, but well skip that and jump to something more fun. Now its a perfect square. Big deal! Well, suppose you change dimensions again; this time youll use setSize.
Make the width and height pixels. Use the already created reference, myDiv1: Figure 2. What happens when you execute this line of code? Does it animate and have a bouncing effect? Thats better! Essentially, the setSize method is the composite of setHeight and setWidth. For this method, you passed the target width and height, and an object with two properties, duration and easing.
Ext JS conveniently wraps many of these methods with the Ext. Lets have some fun creating child nodes. To create a child node, use Elements createChild method: This code adds a string node to the innerHtml of your target div.
What if you wanted to create an element? Easy as pie: This use of createChild will append a child div with the string 'Element from a string' to the innerHtml of div1. We dont like to append children this way because we find the string representation of elements to be messy. Ext JS helps you with this problem by accepting a configuration object instead of a string: Here, youre creating a child element by using a configuration object.
You specify the tag property as 'div' and html as a string. This technically does the same thing as the prior createChild implementation but is cleaner and self-documenting. What if. With the configuration object approach, you can achieve this with ease: In this code youre creating one last child, with an id, a bit of styling applied, and a child element, which is a div with some more styling.
You see all of the additions to myDiv1, including the live DOM view from Firebug, showing that you added a string node and three child divs, one of which has its own child div. If you wanted to inject a child at the top of the list, youd use the convenience method insertFirst, like this: If you want to target the insertion of a child node at a specific index, the createChild method can take care of that task. All you need to do is pass it the reference of where to inject the newly created node, like this: In this code, youre passing two arguments to createChild.
The first is the configuration object representation of the newly created DOM element, and the second is the DOM reference of the target child node that createChild will use as the target to inject the newly created node.
Please keep in mind the id that you set for this newly created item; youll use it in a bit. Notice that youre using myDiv1. Element gives you the opportunity to use all of the generic browser element-management goodness by means of the dom property. The Element. As you can see, the node insertions functioned as intended. You used insertFirst to inject a new node at the top of the list and createChild to inject a node above child node 3.
Remember always to start with the number 0 instead of 1 when counting child nodes. Adding is something that you do often as a web developer. But its equally important to know how to remove something. Lets see how to remove some of the child elements using Ext.
Removing child nodes Removing nodes could be considered much easier than adding them. All you need to do is locate the node with Ext JS and call its remove method.
To test out removal of. Create a new page with the following HTML: Examining this HTML, you find a parent div with the id of 'div1'. It has five direct descendants, the first of which has the id of 'child1'. The second and third children have no ids, but they have CSS classes of 'child2' and 'child3'. The fourth child element has an id of 'child4' and a CSS class of 'sameClass'. Likewise, it has a direct child with an id of "nestedChild1" and the same CSS class as its parent.
The last child of div1 has no id or CSS class. The reason you have all this stuff going on is that youre going to start to use CSS selectors as well as directly target the ids of the elements. Element class and using its create methods.
To remove a child node, the approach is different. You need to specifically target the node thats to be removed. Using the new DOM structure, lets practice a few ways of doing this. The first approach removes a child node from an already-wrapped DOM element. Youll create an instance of Ext. Element wrapping div1 and then use it to find its first child node using a CSS selector: In this example, you create a reference to div1 using Ext.
You then create another reference, firstChild, to the first child using the Element. You pass a pseudo class selector, which causes Ext JS to query the DOM tree within the context of div1 for the first child, which is a div, and wrap it within an instance of Ext. It so happens that the element thats found is the one with the div id of 'child1'. You then call firstChild.
Heres how you could remove the last child from the list using selectors: This example works similarly to the previous one. The biggest difference is that you use the selector 'div: After that, you call lastChild. If youre new to CSS selectors, we advise visiting the following W3C page, which has a plethora of information on selectors: What if you want to target an element by an id?
You can use Ext. This time, youll create no reference and instead use chaining to take care of the job: Executing this code removes the child node with the id of 'child4' and its child node.
Always remember that removing a node with children will also remove its child nodes. NOTE If youd like to read more about chaining, Dustin Diaz, an industryleading developer, has an excellent article on his site at www. The last task well look at is using Ext.
Using Ajax with Ext. Element The Ext. Youll need to first write an HTML snippet to load: This is an HTML fragment. It uses chaining to execute the results of that call, to execute its highlight method.
Save this file as htmlFragment. Next, youll perform the load of this snippet: In this snippet, you call the load method of the result of the Ext. What happens when you execute this code?
See figure 2. When you execute this code snippet, youll see that the document body performs an Ajax request to retrieve your htmlFragment. While the file is being retrieved, it shows a loading indicator.
Using templates and XTemplates The Ext. Template class is a powerful core utility that allows you to create an entire DOM hierarchy with slots that can be filled in later with data. Once you define a template you can use it to replicate one or more of the predefined DOM structures, with your data filling in the slots.
Mastering templates will help you master UI widgets that. Using templates Youll start out by creating an extremely simple template, and then youll move on to create one thats much more complex: In this example, you create an instance of Ext. Template and pass it a string representation of a div with a slot, which is marked in curly braces, and you store a reference in the variable myTpl.
You then call myTpl. Do this three consecutive times, which results in three divs being appended to the DOM, with each different first name filling in a slot. As you can see, three divs were appended to the document body, each with a different name. The benefits of using templates should now be clear. You set the template once and apply it to the DOM with different values. In the previous example, the slots were integers in curly braces, and you passed in single-item arrays.
The following listing shows how to create a template that uses such syntax. Listing 2. When creating this complex template B the first thing youll probably notice is that you pass in quite a few arguments.
You do this because, when creating a template,. The Ext JS developers were keen on this idea, so they programmed the Template constructor to read all of the arguments being passed, no matter how many there might be.
The first is color, which will be used to style the background of the element. The three other data points are name, age, and dob, which will be directly visible when the template is appended.
The next step is to compile c your template, which speeds up the template merging data with the HTML fragment by eliminating regular expression overhead. For these two operations you dont technically need to compile it because you wouldnt see the speed benefits; but for larger applications where many templates are stamped out, compiling has a clear benefit.
To be safe, we always compile templates after instantiating them. Last, you perform two append calls d where you pass in the reference element and a data object. Instead of passing an array as you did in your first exploration of templates, you pass in a data object, which has keys that match the template slots. What if you had an array of objects?
For instance, what if an Ajax request returned an array of data objects, and you needed to apply a template for each data object? One way to handle this is to loop through the array, which is easily done with a generic for loop or the more robust Ext. I say nay to that approach. Id use XTemplates instead, which makes the code much cleaner. Looping with XTemplates XTemplates technically can be used for single data objects, but they especially make life much easier when you have to deal with looping through arrayed data to stamp out HTML fragments onscreen.
The XTemplate class extends Template and offers much more functionality. Youll start your exploration by creating an array of data objects, and then youll create an XTemplate, which youll use to stamp out HTML fragments, as shown in the next listing.
In listing 2. Next, you instantiate an instance of XTemplate c, which looks much like the last Template configuration, except you encapsulate the div container with a custom tpl element with the attribute for, which contains the value ". The tpl tag is like a logic or behavior modifier for the template and has two operators, for and if, which alter the way the XTemplate generates the HTML fragments. In this case, the value of ".
The results of your efforts are identical to the template example, as shown in figure 2. Remember, the advantage of using XTemplates in this case is that you dont have to write code to loop through the array of objects. You let the framework do the dirty work for you. The capabilities of XTemplates extend far beyond merely looping through arrays, which increases its usability exponentially. Advanced XTemplate usage You can configure XTemplates to loop through arrays within arrays and even have conditional logic.
The example in the next listing will flex some XTemplate muscle and demonstrate many of these advanced concepts. Some of the syntax youre about to see will be foreign to you. Dont get discouraged. Well explain every bit. Well use the previous tplData from listing 2. This use of XTemplate demonstrates quite a few advanced concepts, the first of which is looping within a loop B. Remember, the for attribute instructs the XTemplate to loop through a list of values.
In this case, the for attribute has the value of 'cars', which differs from the value thats set for the first for attribute, ". Remember that cars is an array of strings. In simple terms, the name of a car will be rendered at this position. Next, you see a tpl behavior modifier with an if attribute d, which executes this. The this. Well talk more about this in a bit. The if attribute is more like an if condition, where the XTemplate will generate HTML fragments if the condition is met.
In this case, this. The values property is an internal reference of the values for the array youre looping through. Because youre looping through an array of strings, it references a single string, which is the name of a car.
The last item of interest is the object that contains your isCamry method f. Including an object or reference to an object with a set of members with the passing arguments to the XTemplate constructor will result in those members being applied directly to the instance of XTemplate itself.
This is why you called this. All of these member methods are called within the scope of the instance of XTemplate for which theyre being passed.
Element to stamp out HTML fragments with data. We encourage you to look over the template and XTemplate API pages for more details and examples of how to use these utilities. Your next exposure to templates will be when you learn how to create a custom ComboBox. Remember that browsers typically have their own way of publishing when the DOM is ready for manipulation, which causes a code-management nightmare.
In working with Ext. You then took an in-depth look at the Ext. Element class, which wraps and provides end-to-end management for DOM nodes.
You explored a few of the management utilities for DOM nodes by adding and removing elements. All UI widgets use the Ext. Element, making it one of the most-used components of the core framework. Each widgets element can be accessed via the public getEl method or the private el property, but only after its been rendered. You also jumped into advanced techniques with XTemplates and learned how to embed behavioral modifying logic into the template definition itself, producing results depending on the data provided.
Looking forward, youll focus on the UI side of the framework and delve right into the core concepts and models that drive the framework. I Jay recall my early days with the Ext framework, when I learned by toying with the examples and reading the API documentation.
I spent many hours on some of the most important core UI concepts, such as adding user interaction, reusing widgets, and understanding how one widget can contain or control another. For instance, how would I make clicking an anchor tag display an Ext window?
Likewise, I needed to know how to get widgets to communicate with each other. For example, how would I reload a grid panel when a row of another grid panel was clicked? Also, how would I add child items dynamically to and remove them dynamically from a panel? How could I find a particular field within a form panel based on the type field? In this chapter youll explore the deep caverns of the fundamental UI building block, the Component class, and learn how it serves as the central model for all UI widgets by implementing a template for standard behaviors known as the component life cycle.
Well also discuss the Container class, and youll get an in-depth look at how widgets can manage child items. Youll learn how to dynamically add items to and remove them from widgets like the panel, which can be used as a building block for dynamically updating UIs. The Component model The Ext JS Component model is a centralized model that provides many of the essential component-related tasks, including a set of rules, known as the component life cycle, that dictate how the component instantiates, renders, and is destroyed.
Well cover the component life cycle in section 3. All UI widgets are subclasses of Ext. Component, which means that all of the widgets conform to the rules dictated by the model. Figure 3. Clojure in Action, 2nd Edition. Clojure in Action, 2nd Edition is an expanded and improved version that's been updated to cover the new features of Clojure 1.
The book gives you a rapid introduction to the Clojure language, moving from abstract theory to practical examples. You'll start by learning how to use Clojure as a general-purpose language. Next, you'll explore MongoDB in Action, 2nd Edition.
MongoDB in Action, 2nd Edition is a completely revised and updated version. It introduces MongoDB 3. This perfectly paced book gives you both the big picture you'll need as a developer and enough low-level detail to satisfy system engineers. MongoDB in Action, 2nd Edition is a completely revised a Camel in Action, 2nd Edition.
Apache Camel is a Java framework that implements enterprise integration patterns EIPs and comes with over adapters to third-party systems. By using Camel, you benefit from the testing and experience of a large and vibrant open source c Remote method invocation with Ext Direct Making the two ends meet.
No prior experience with Ext JS is required.