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

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

Hibernate Derived Properties – @Formula Annotation

HibernateIn Hibernate a derived property (also called a calculated property) is a read-only property whose value is calculated at fetch time using SQL expressions.

Example: For an employee entity with properties such as an id and the employee name also a monthlySalary property, you might also want to have a yearlySalary which is not necessarily stored in the database.

package net.ozar.exp.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="EMPLOYEE")
public class Employee implements java.io.Serializable {

	private static final long serialVersionUID = -7311873726885796936L;

	@Id
	@Column(name="ID")
	private Integer id;

	@Column(name="FIRST_NAME", length=31)
	private String firstName;

	@Column(name="LAST_NAME", length=31)
	private String lastName;

	@Column(name="MONTHLY_SALARY")
	private float monthlySalary;

	public Employee() {
	}

	// getters and setters
     // ...

	public float getMonthlySalary() {
		return monthlySalary;
	}

	public void setMonthlySalary(float monthlySalary) {
		this.monthlySalary = monthlySalary;
	}

     /* This artificial property - as I call it - is a kind of a calculated property, but not with Hibernate derived property support - not just yet */
	public float getYearlySalary() {
		return this.monthlySalary * 12;
	}

}

The above example gives us a simple calculation in memory for just screen output without Hibernate’s derived property or the @Formula support.  Now take a moment to reflect that we need all the employees whose yearly salary average is above $5000. Then what? In this case, you might wanna make use of Hibernate’s derived property feature.
Continue reading