Win a free copy of my book MySQL Management and Administration with Navicat

MySQL Management and Administration with Navicat

MySQL Management and Administration with Navicat

I am pleased to announce that I have teamed up with Packt Publishing and we are organizing a giveaway especially for my recent book.

All you need to do is just comment about the book below the post, and win a free e-copy of MySQL Management and Administration with Navicat.

Three lucky winners stand a chance to win a  free copy of the e-book. Keep reading to find out how you can be one of the Lucky Ones.

Overview of MySQL Management and Administration with Navicat

  • Master Navicat’s visual design tools and editors with thorough examples
  • Tips, tricks and fast-paced tutorials for getting the most out of Navicat

Read more about this book and download a free sample chapter: http://www.packtpub.com/mysql-management-administration-with-navicat/book

How to Enter?

All you need to do is head on over to this page and look through the product description of these books, and then drop a line via the comments below to let us know what interests you the most about this book. It’s that simple!

Continue reading

A Simple JSF Tutorial with PrimeFaces and JSON Object Parsing in Java

In this tutorial, you will see an example of parsing JSON objects containing exchange rates for certain currencies and displaying them on a web page using JSF 2.1 and PrimeFaces 2.2 which is a rich-component framework for JSF adding AJAX and Web 2.0 capabilities to your web application.

What you need for this tutorial

  • Oracle JDK 1.6 or later
  • Netbeans 7.0 or later (if you choose a different IDE, you will need to manually get the necessary libraries and components for this tutorial. See the following section)
  • Tomcat 7

Technologies and libraries used

  • JSF 2.1 (Mojarra 2 libraries a.k.a. jsf-api.jar, jsf-impl.jar, jstl.jar and standard.jar)
  • PrimeFaces 2.2.1
  • JSON (for Java)
  • commons-logging-1.1.1.jar
  • log4j-1.2.16.jar
  • httpcore-4.1.4.jar
  • httpclient-4.1.3.jar

Setting up the Project with JSF 2 and PrimeFaces Support

Launch Netbeans, and then go along the following steps:
Continue reading

Some thoughts on JSF…

Developed through the Java Community Process (JCP) by a group of technology leaders, including Sun Microsystems later acquired by Oracle, Borland, BEA, and IBM, along with a collection of Java and Web experts well known in the industry under JSR – 314, Java Server Faces technology establishes the standard for building server-side user interfaces. With the contributions of the expert group, the JavaServer Faces APIs are being designed so that they can be leveraged by tools that will make web application development even easier.

What is JSF?

JSF LogoJSF is a request-driven MVC web framework based on component-driven UI design model, using XML files called view templates or Facelets views. Requests are processed by the FacesServlet, which loads the appropriate view template, builds a component tree, processes events, and renders the response (typically HTML) to the client. The state of UI components (and some other objects) is saved at the end of each request (called state saving), and restored upon next creation of that view. Several types of state-saving are available, including client-side and server-side state saving. Out of the box, JSF 1.x uses Java Server Pages (JSP) for its display technology, but can also accommodate other technologies (such as XUL and Facelets). JSF 2 uses Facelets by default for this purpose. Facelets is a more efficient, simple, and yet more powerful view description language (VDL).

What’s the difference between JSF and JSP/Servlets?

JSP (Java Server Pages) is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports the so-called tag libraries shortly denoted as taglibs which are backed by pieces of Java code with which you can control the page flow and/or output dynamically (programmatically). A well known taglib is JSTL. JSP also supports the Expression Language which can be used to access back-end data (actually, the attributes which are available in page, request, session and application scopes), mostly in combination with taglibs.

When a JSP is requested for the first time or when the web application starts up, the servlet container will compile it into a servlet, which is a class extending HttpServlet and use it during the lifetime of the web application. In Tomcat, for example, you can find the source code of the generated servlet in the server’s work directory. On a JSP request, the servlet container will execute the compiled JSP class and send the generated output (usually just HTML/CSS/JS) through the web server over the network to the client side which in turn displays it in the web browser.

Continue reading

Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part IV

Seam Tomcat Deployment Tutorial Part 4
In this part of the tutorial we will correct the bugs inherent in version 2.2 of Seam-gen and we will add some code to spice up our blog CMS.

First of all, our PostEdit.seam page is not working at all as it is. We shall fix this:

Fixing the PostEdit.xhtml page

Figure 4.1 - Fixing the PostEdit.xhtml page

Open PostEdit.xhtml from the WebContent folder and find the <rich:tabPanel switchType=”ajax”> block. This is what’s causing the problem, because it has more than one tab – one to have the user select a category from a grid on another page, and the second one for selecting a user, since these two entites have @ManyToOne relationships to the post entity, and Seam-gen can’t handle generating more than one joined object selection user interface item in this version.

I don’t want an external grid for selection of a category anyway, so we will delete the entire <rich:tabPanel> block on this page, and instead make the category selectable from a pop-up menu using a typical JSF selectOneMenu UI component.

After you delete the <rich:tabPanel> go towards the beginning of the page and locate the code block starting with <s:decorate id=”titleField” template=”layout/edit.xhtml”>.
Within that block replace <h:inputTextarea id=”title” cols=”80″ rows=”2″ required=”true” value=”#{postHome.instance.title}”/> with <h:inputText id=”title” required=”true” value=”#{postHome.instance.title}”/>

Next, add the following code block below the closing tag (</s:decorate>) for titleField:

           <s:decorate id="categoryField" template="layout/edit.xhtml">
                <ui:define name="label">Post Category</ui:define>
                <h:selectOneMenu id="category"
                           required="true"
                              value="#{postHome.instance.title}">
                     <s:selectItems value="#{categoryList.resultList}" var="cat" label="#{cat.name}" noSelectionLabel="Please select..." />
                     <s:convertEntity />
                </h:selectOneMenu>
            </s:decorate>

Continue reading

Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part III

Seam Tomcat Deployment

In this part III of the tutorial, we’ll build the entity classes from the database we created in Part I and configure the Seam project we created in Part II so as to make it fully compatible with Apache Tomcat.

Creating The Model Layer

We’ll use Hibernate‘s reverse engineering tool (hbm2java) embedded in Seam-gen to create the entity classes from the database we created in part 1.

Seam Generate Entities

Figure 3.1 - Generating entities from database in JBoss Seam

Right-click the project blog in project explorer and select New > Seam Generate Entities.

Continue reading

Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part II

JBoss Seam - Tomcat

In part I of the tutorial, I provided the instructions about the development environment and  how to create the blog’s database. In this part II, using Eclipse’s JBoss tools plugin, we’ll create and configure the JBoss Seam web project and prepare it for full Tomcat-compatibilty and for the creation the basic CRUD (create, read, update and delete) functionality of entities which will be reverse engineered from the database using hbm2java embedded in Seam-gen whose GUI version comes built-in with JBoss Tools.

The Development Environment

To be able to follow the tutorial and reproduce the same results, it’s best (if not mandatory) that you have exactly the same version of the tools and plug-ins I mentioned in the previous post. As of this part (and so on) I’ll instruct on Eclipse Helios with JBoss Tools 3.2. You can also refer to my post titled ‘Matrix of compatible platforms and runtimes with JBoss Tools‘ to see which version of Eclipse and other stuff (such as Seam framework version) is compatible with which version of JBoss tools plugin, etc.

So here we go. Now launch Eclipse if you already haven’t done so.

Changing perspective in Eclipse

Figure 2.1 - Changing perspective in Eclipse

First of all, we shall change the perspective in Eclipse to Seam – that option, however, is only available if you have JBoss tools installed. See figure 2.1 and 2.2.
Continue reading

Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part I

Tired of simple hello world tutorials or tutorials taking you only as far as user login and registration examples? Here’s an intermediate-level tutorial in which I will demonstrate how to make a blog CMS application using JBoss Seam incorporating JSF (w/Facelets), Hibernate JPA and how to deploy it to Apache Tomcat web server. With this tutorial, I also aim to provide complete and correct instructions for preparing a Seam 2.2 project to be deployed on Tomcat without errors.

JBoss Seam Project on Tomcat

The blog we’ll make in this tutorial is simple, but the tutorial itself is not.

Here’s a list of technologies and frameworks with their versions which we will use here:

  • Java EE 5 (on JRE 6)
  • JBoss Seam 2.2.2 (incorporating JSF 1.2 + Facelets, RichFaces 3.3.3 and Hibernate JPA 1.0)
  • Apache Tomcat 6.0
  • MySQL 5.1 (community edition)

And the tools we will use such as the IDE and the database GUI administartion tool:

Continue reading

Best 5 Java open-source web application frameworks

JSF

Some programmers think JSF has a steep learning curve

When it comes to developing web applications using Java, writing all the code from scratch has its advantages if you’re trying to master a new technology, but for real life web applications, you have to go for a framework as many expert developers would agree. Otherwise you risk a great deal of failure because of having allocated too much time and too many resources by re-inventing the wheels.

There are some hardliners who still argue why there’s ever a need for a framework, since everything can be accomplished by Servlets, JSP and Filters. One of them is Bear Bibeault author of JQuery in Action.

-Adeel Ansari

The cost is an important factor—although “free” in most cases also means widespread usage, community support, and no dependence on a single vendor. It takes some time for developers to get used to a framework and be good at it. Therefore choosing a framework as a long-term strategy. You cannot be switching frameworks for every project. Sticking with one framework also helps as once the expertise in that framework builds up; customizing the framework also becomes a possibility.

A tempting option is for organizations to build their own framework to address needs specific to the kind of work the organization undertakes. Although it does seam seem to make sense on paper, for my money, this is a suicidal strategy. Thoroughly testing and maintaining a framework is a huge task that will need dedicated human resources. These few people would become critical and the only source of support for others using that framework. Also, with so many quality frameworks available for free, I seriously doubt it really is necessary.

As with many web frameworks emerging nowadays, the ever-increasing number of Java web application frameworks out there today is intimidating for many developers even to look into because of being presented with too many choices. However, matching the criteria of popularity, widespread usage and tooling support, I can list a few of the best Java web application frameworks here and in a descending order of my personal choice. Sorry if I haven’t listed your favorite Java web framework here, feel free to agree or disagree in the comments section. Continue reading

Matrix of compatible platforms and runtimes with JBoss Tools

JBoss Tools Icon
Use Eclipse with the JBoss Tools plugin instead of  JBoss Developer Studio? It can get somewhat tricky to get the right version of the tools plugin to work with the compatible version of Eclipse and the correct version of JSF components, etc.

JBoss Dev Studio is a branded version of a Eclipse packed with the right version of JBoss Tools. The dev studio is usually bundled with a developer subscription from RedHat for $99. (I’ve been told, however, by Max Rydahl Andersen a JBoss employee who is also one of the developers of JBoss tools and the developer studio that the JBoss Developer Studio IDE itself is actually free without the JBoss commercial runtimes – i.e. JBoss EAP).

If you stick with Eclipse IDE with the JBoss tools plugin, I came up with the following matrix of the set of tools showing the coupling of compatible versions.

JBoss Tools Compatibility Matrix

EclipseJBoss ToolsJBDSJBoss EAPJBoss AS (Community)SeamJSFRichFaces
3.6 / Helios3.23.0.04.3,5.0,5.15.1, 5.0, 4.2, 4.0, 3.22.2, 2.1, 2.0, 1.22.0 (in VPE), 1.2, 1.13.3.x
3.5/Galileo3.1.03.0.04.3, 5.05.1, 5.0, 4.2, 4.0, 3.22.2, 2.1, 2.0, 1.22.0 (in VPE), 1.2, 1.13.3.x
3.4.2/Ganymede3.0.x2.1.04.3, 5.05.0, 4.2, 4.0, 3.22.2, 2.1, 2.0, 1.21.2, 1.13.3.1
3.3.2/Europa2.1.21.1.04.35.0, 4.2, 4.0, 3.22.0, 1.21.2, 1.13.3.0
3.3.1.1/Europa2.0.11.0.04.24.2, 4.0, 3.22.0, 1.21.2, 1.13.1.0
Continue reading