One of the most interesting mathematical stuff is Permutation. A permutation is the act of re-arranging all the members of a set into some sequence or order, such that the order of selection always matters (unlike combination).

Assume that we have 3 balls (Red, Green and Blue). If we want all the possible permutation then we will have the following 6 possible permutation:

Red, Green, Blue.

Red, Blue, Green.

Green, Blue, Red.

Green, Red, Blue.

Blue, Red, Green.

Blue, Green, Red.

Mathematically, the number of permutations of n distinct objects is n factorial usually written as n!. Now, let’s write a simple function in JavaScript that gets the unique permutation for a set of objects.

As shown in Util.getPermuts, it takes three parameters as follows:
1. array parameter represents the array of objects that we have.
2. start parameter represents the current start index.
3. output parameter represents the array that holds all the possible arrays of permutations.

Util.getPermuts recursively swaps the array elements in order to get all the possible permutations of the input array.

The previous code covers permutation without repetition which means that we use every element that we have only once in every possible permutation.

What about if we want to get all the possible permutations with repetition. Assume that we have 4 blank papers and we would like to paint them with all the possible ways using Red, Green and Blue colors.

Can you write a JavaScript function that can get all the possible 4 papers’ paintings?

According to Permutation with repetition, all the possible 4 papers’ paintings with 3 colors can be calculated as (3 power 4) which equal to 81. The formula is very simple: n P(with repetition) r = n ^ k.

Now, let’s use recursion in order to get all the possible permutation with repetition.

As shown in Util.getRPermuts, it takes four parameters as follows:
1. array parameter represents the array of objects (colors in our case) that we have.
2. size parameter represents the size of every permutation item.
3. initialStuff parameter represents a temp array that holds every possible permutation with repetition.
4. output parameter represents the array that holds all the possible arrays of permutation with repetition.

In order to know all the possible 4 papers’ paintings using the available 3 colors, you can call the permutation with repetition API simply as follows:

@Wednesday, March 25 04:00 PM, I will be speaking in JavaLand Germany conference (that will be held from 24 March to 26 March @Brühl, Germany) about “Developing Mobile Applications using JavaScript”. My session will be a practical one, I will discuss mobile apps development using JavaScript and Apache Cordova. My session will also include Apache Cordova Integration tips with jQuery mobile on the three popular mobile platforms (Android, iOS and Windows Phone 8).

There is a JavaScript quiz at the end of my session, the one who will be able to answer it correctly will have a free copy of my new JavaScript book:

As shown in Util.getAllPossibleCombinations, it takes five parameters as follows:
1. array parameter represents the array of objects that we have.
2. size parameter represents the size of every selection from the array.
3. start parameter represents the current start index.
4. initialStuff parameter represents a temp array that holds every possible combination.
5. output parameter represents the array that holds all the possible arrays of combinations.

In order to know all the possible 4 balls selections from the available 6 balls, you can call the API simply as follows:

In the past, only desktops or laptops could be used to create computer programs. However, thanks to technological advancements, today’s smartphones can now be used in the creation of software.

Mobile apps that can be used to create programs on the go were made in order to hasten the development process of apps, which is quite possibly the most lucrative business today. In a study featured on entertainment site Pocket Fruity, it was discussed that more and more people take their smartgadgets wherever they go, may it be at a train station, on a bus, or in a pub. Since the app-making industry is extremely cutthroat, developers created an edge in the form of apps in order to beat deadlines even when they’re not at their workstations.

Here are two useful mobile apps for the web devs out there.

The C Programming Language App

This is one of the best apps for the C programmers out there. It is a handy app for scribbling down codes as well as checking codes thanks to its Reference Tab. The reference tab has links to the language reference, string library, math library, and standard library.

The C Programming Language has a feature that allows developers to test whether or not a program will run smoothly on a chosen platform. It also allows users to easily send their codes via email once they’re done. The app can be used for free by iOS users.

JavaScript Anywhere

JavaScript Anywhere is a three-in-one app that acts as a Java Script, CSS, and HTML editor. It has a very simply user interface so developers can get the hang of using it quickly. Like the C Programming Language App, JavaScript Anywhere allows users to check whether or not their program will work smoothly. Users can import saved projects via the Internet and even store their work on Dropbox for backup. Jsany can also be downloaded for free by iOS users.

Form Fields Navigation and Changing the text of “Done” button

It will be nice to change the text of the "Done" button based on the current text focus. This means that if the user name text field is focused then the "Done" button will be renamed to "Next". When the user clicks "Next" button, the password text field will be focused.

If the password text field is focused then the "Done" button will be renamed to "Go". When the user touches "Go" button, the keyboard will hide and the login logic will be executed.

In order to implement the form field navigation, we need to implement the UITextFieldDelegate protocol’s textFieldShouldReturn(theTextField: UITextField!) -> Bool function in our ViewController. Note that userNameText and passwordText delegate should be set to self during viewDidLoad().

The previous code means that if the user name text field is focused and the user touches "Done" button then the password text field will be focused by calling self.passwordText.becomeFirstResponder(). if the password text field is focused and the user touches "Done" button then the keyboard be hidden by calling textField.resignFirstResponder() and after this we can call the login logic.

Note: both passwordText and userNameText are outlets for the text fields.

For changing the the text of "Done" button for passwordText and userNameText text fields, this can be done by changing the Return Key value in the text field properties as shown in the figure below.

Implementing the login logic

Finally, we can implement the login logic which is simply mocked by an Alert message as shown below.

Attached below the review of Werner Punz (Senior software developer for Irian GmbH, Apache MyFaces Committer, and a member of the JSF Expert Group) about the “Pro JSF and HTML5″ book:

Pro JSF and HTML5 Book

Good but not perfect

“The book itself is a crash course in JSF with extensive JSF 2.2 coverage and component coverage.

The first part of the book is an introduction into JSF and JSF 2.2, the second part walks you through component creation the third part covers two of the most widely used component libs and the fourth part walks you through an entire JSF application utilizing Java EE 7.

Well what should I say, while I wished some parts were covered more deeply, like the already extensive component creation part or the Java EE application walk-through which should have gotten more explanatory coverage in the Java EE area, I personally guess that the book as JSF 2.2 reference and as a tutorial book for JSF fulfills its purpose very well.

The problem I see simply is if you want to cover component creation for JSF on its own with all the special cases for different component types, you probably need a book on its own, the same goes for a full blown Java EE application with all its little details on which pattern to apply where and why, this would be also another book which then should omit the JSF tutorial part.

I will give the book 4 stars as very good JSF 2.2 and component creation reference and good JSF tutorial, but one star less due to the lack of depth especially in the application walk-through which should have gotten a bit more explanation on the Java EE side of things.”

“Fabulous coverage of a powerful and mature cross-platform library. The book goes through the basics over the first five chapters, making sure native app developers aren’t alienated by the diaspora of HTML5/CSS3 web standards out there. A web developer will find that the book truly gets into its stride via the 5th, 6th, 7th and 8th chapters – which cover advanced Cordova API calls, platform specific code for iOS/Android/WinPhone, unit testing (critical) and finally a “Mega App” that puts your knowledge through some practical pacing.”

The book in Amazon:

One of the wonderful features of the upcoming JSF 2.3 is the ability to inject many JSF objects such as UIViewRoot, ViewMap, ApplicationMap, ExternalContext and FacesContext. In this post, I will show you how to simply inject FacesContext without having to use the old way FacesContext.getCurrentInstance().

Continuing working on the sample that was introduced in the previous post, let’s modify User managed bean to get FacesContext in order to display an information message to the user once the operation is done. The following code snippet shows the modified User managed bean.

As shown, all what you need to inject FacesContext in your managed bean is to annotate its declared instance with @inject annotation.

Running Application on GlassFish 4.1

In order to run our JSF application this time on GlassFish, we need to build Mojarra jars for GlassFish and then configure them on the server as follows:

First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.

Check out Mojarra 2.3 source code using the following SVN command:

svn checkout https://svn.java.net/svn/mojarra~svn/trunk

In order to build the JSF Mojarra jars for GlassFish then create a new file called build.properties under trunk. Then copy build.properties.glassfish file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.

# --------------------------------------------------
# Set this to the directory in which the sources
# were checked out into
# --------------------------------------------------
jsf.build.home=/Users/hazems/projects/mojarra23/trunk

CD to the jsf.build.home path, and then execute the following ant command:

ant clean main

After the successful execution of the previous command, you can get Mojarra jars from:

jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.

javax.faces.jar from trunk/jsf-ri/build/lib directory.

Finally, overwrite the default javax.faces.jar file under glassfish-4.1/glassfish/modules with the new built javax.faces.jar file, and deploy our JSF application to GlassFish. After running our JSF application, you can see the information message after clicking "Greet" button as shown below.

It is really not so early to start working with the upcoming JSF 2.3 and testing it. In this post, I will show you how to get started in JSF 2.3 by building JSF (Mojarra) jars from its source then use them for your JSF 2.3 application which will run in Tomcat 7.

Building JSF Jars from SVN:

First of all, you need to make sure that you have both SVN and Apache Ant installed and configured in your operating system.

Check out the source code using the following SVN command:

svn checkout https://svn.java.net/svn/mojarra~svn/trunk

In order to build the JSF Mojarra jars for Apache Tomcat then create a new file called build.properties under trunk. Then copy build.properties.tomcat file (which is located directly under trunk) content into it. Do not forget to set jsf.build.home property to the directory in which the sources were checked out into as follows for example.

# --------------------------------------------------
# Set this to the directory in which the sources
# were checked out into
# --------------------------------------------------
jsf.build.home=/Users/hazems/projects/mojarra23/trunk

CD to the jsf.build.home path, and then execute the following ant command:

ant clean main

After the successful execution of the previous command, you can get Mojarra jars from:

jsf-api-intermediate.jar from trunk/jsf-api/build/lib directory.

javax.faces.jar from trunk/jsf-ri/build/lib directory.

Configuring your first JSF 2.3 application:

Simply all what you need to work with JSF 2.3 in Tomcat 7 is to do the following:

Place the two Mojarra jars in step 4 in your web application WEB-INF/lib folder.