Alloy

Whats Alloy?
 Ans:
Alloy is a UI meta framework that provides a consistent and simple API for building web applications across all three levels of the browser: structure, style and behavior.  This framework is built on the top of YUI3.It supports HTML5 as well as CSS3. Its a separate project of Liferay. To know more about Alloy visit http://alloy.liferay.com. 

To do some sample examples lets download alloy from here . The link will download a file alloy-1.0.1.zip which indicates that 1.0.1 is the current version of alloy. Unzip the file in your local drive. The unzipped folder looks  like the following



You can explore various demos of Aolloy inside the demos folder. Lets do some examples using alloy javascript library. aui.js is the alloy javascript libray that's available under build\aui folder.We will create Alloy_practice folder where we will copy the aui.js file inside it. You can do as your own way. Now create a sample html file inside Alloy_practice include aui.js file as bellow


<script src="aui.js" type="text/javascript"></script>

Now we are ready to explore Alloy javascript library.

Alloy Ready Function:
If you know jQuery then probably you know the use of ready function.In alloy its of the following form

AUI().ready(function(A) {


});

When the DOM is ready or in simple language when the whole HTML is loaded  the above function will be called. So the good practice is to keep your code inside the ready function. We can give alert inside the  ready function to check how does it work.


AUI().ready(function(A) {
    alert(A);
});

So when the function will be called you will get the instance of Alloy which will be assigned to the variable 'A' and you should get an alert message of the contents of 'A' variable. Letter we can use this A variable to access various functions of Alloy Library.

Alloy Module:
There are many modules available in Alloy. So what does it mean? The answer is very simple. Its a single unit of work which can be used for specific task, purpose. If you want to add auto complete functionality by jQuery then probably you will download plugin for it and add it in your jsp or html page.But the alloy framework is something different. This kind functionality is already available with Alloy and just we need to use it as same import statement in java. Some of the modules in Alloy are

aui-autocomplete
aui-calendar
aui-color-picker
etc...
To know more about Alloy modules click here.
So how to use Alloy module? Its very simple..........


AUI().ready('aui-autocomplete',function(A) {


});

The above will load Auto Complete module. Is not it simple? We can load multiple modules as bellow.......


AUI().ready('aui-autocomplete','aui-calendar',function(A) {


});

We can add number of modules as many as required. Just remember that function(A) should always be in the last.

Get element by id and name in Alloy:
I believe that you know at least javascript. I am sure that you used get element by id or by name.This is very simple in Alloy.Lets see the bellow code

<input type="text" id="mytext" value="xyz"/>

To get the value of the above text box we can write the following code

AUI().ready(function(A) {
    var inputValue = A.one('#mytext').get('value');
});

Here we are using A.one() since there are only one element with the id mytext. Otherwise we can use A.all() for multiple occurrence of an element. #mytext represents element with id mytext and get('value') gives the value of the text box.Similarly for the bellow element

<input type="text" name="mytext" value="xyz"/>  

We can extract the value of the text box as bellow

AUI().ready(function(A) {
    var inputValue = A.one('input[name=mytext]').get('value');
 });













17 comments:

  1. Thanks, it was helpful.
    Can you please post also some example about Ajax calls with Alloy UI?

    Thank you again

    ReplyDelete
  2. Hi,
    try you see at http://musarra.wordpress.com/2012/12/18/alloy-ui-autocomplete-ajax-example/

    Bye,
    Antonio.

    ReplyDelete
  3. Hi,
    I realize that the latest stable version of alloy UI is 1.0.1. However there a newer versions available via github with various fixes which we are looking at. For instance an issue with charts not refreshing in IE using allow UI is fixed is version 1.7.1, but there's no way for us to download these versions. Can you let us know if there is a separate location from where we can download these?

    ReplyDelete
  4. thanks for your such kind information

    ReplyDelete
  5. It was very useful post and the alloy 20 is just a nickel-Alloy- chromium austenitic alloy formulated to acid episode, especially sulfuric acid for utmost weight. This superalloy includes a high resistance to deterioration corrosion in compounds containing sulfuric phosphoric and nitric acids. In addition it includes niobium for stabilization against sensitization and resulting intergranular corrosion. alloy 20 pipe | alloy 20 pipe

    ReplyDelete
  6. Can you please post an article how dynamic content can be presented using Alloy

    ReplyDelete
  7. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog.
    It is very nicely explained. Your article adds best knowledge to our Java Online Training from India.
    or learn thru Java Online Training from India Students.

    ReplyDelete
  8. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    best rpa training in bangalore
    rpa training in bangalore
    rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  9. Wonderful article, very useful and well explanation. Your post is extremely incredible. I will refer this to my candidates...
    python training in chennai
    python course institute in chennai

    ReplyDelete


  10. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS Training in Bangalore | Best AWS Amazon Web Services…
    Amazon Web Services Training in Pune India
    AWS Online Training in India | AWS Training | AWS online training
    AWS Training in Bangalore | Aws training in Bangalore with placements

    ReplyDelete
  11. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    AWS Training in pune
    AWS Online Training
    AWS Training in Bangalore

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete