Javier has posted 48 posts at DZone. View Full User Profile

OpenXava 4.0: Rapid Java Web Development

11.25.2010
| 10772 views |
  • submit to reddit

OpenXava is a framework for rapid development of business applications using Java. It is easy to learn and one can have an application up in no time. At the same time, OpenXava is extensible, customizable and the application code is structured in a very pure object oriented way, allowing you to develop arbitrarily complex applications.

The OpenXava approach for rapid development differs from those that use visual environments (like Visual Basic or Delphi) or scripting (like PHP). Instead, OpenXava uses a model-driven development approach, where the core of your application are Java classes that model your problem. This means you can stay productive while still maintaining a high level of encapsulation.

The all-new version of OpenXava, OpenXava 4.0, improves significantly the user experience, producing a Rich Internet Application user interface. Additionally, some interesting improvements has been done for the developers, such as Groovy, JPA 2.0 or Dependency Injection.

The best way to taste the new features of OpenXava 4.0 is downloading it and following the Quick Start guide.
Below you have some of the main new features present in OpenXava 4.0.

Better User Experience

The next screenshot of a simple OpenXava 4.0 module shows some of the new features:

Another new useful feature of OpenXava is the use of dialogs. OpenXava use them for creating and editing reference and collection elements, though the developer can show his own dialogs in his own actions. Moreover, the user has the possibility of hidding and showing any frame in the view. So he can hide any reference, group or collection to adapt the user interface to his necessities and preferences. The next screenshot shows these features:

These are only some of the user interface new features. OpenXava 4.0 has around 40 improvements of the user interface.

More Options for Developers

OpenXava 4.0 allows to use Groovy for coding all the parts of your application, now it uses JPA 2.0, you can use Dependency Injection in you actions and the way for doing typical tasks has been simplified.
For example, you can use Groovy to define you entity, as following:

@Entity
@Table(name="TOrder")
@View(members="""
year, number, date;
customer;
details;
amount;
remarks
"""
)
class Order extends Identifiable {

@Column(length=4)
@DefaultValueCalculator(CurrentYearCalculator.class)
int year

@Column(length=6)
int number

@Required
@DefaultValueCalculator(CurrentDateCalculator.class)
Date date

@ManyToOne(fetch=FetchType.LAZY, optional=false)
@ReferenceView("Simplest")
Customer customer

@OneToMany(mappedBy="parent", cascade=CascadeType.ALL)
@ListProperties("product.number, product.description, quantity, product.unitPrice, amount")
Collection<OrderDetail> details = new ArrayList<OrderDetail>()

@Stereotype("MEMO")
String remarks

@Stereotype("MONEY")
BigDecimal getAmount() {
BigDecimal result = 0
details.each { OrderDetail detail ->
result += detail.amount
}
return result
}

@PrePersist
void calculateNumber() throws Exception {
Query query = XPersistence.getManager()
.createQuery("select max(o.number) from Order o " +
"where o.year = :year")
query.setParameter("year", year)
Integer lastNumber = (Integer) query.getSingleResult()
this.number = lastNumber == null?1:lastNumber + 1
}

}

You can use the Java standard for Dependency Injection, JSR-330:x

public class ChangeActiveYearAction extends ViewBaseAction {

@Inject // Standard annotation from JSR-330
private int activeYear; // Getter and setter are not needed

public void execute() throws Exception {
assert activeYear == 2010; // The value from session object
activeYear = 2012; // It changes the value of session object
}

}

Thus the activeYear session object is injected in the activeYear field before call to execute(); and after execute() execution the value of the activeYear field is assigned back to the actionYear session object. So, you can change session objects state from inside an action, even with immutable and primitive types.

There are some improvements to the actions that do not add new functionality, but allows you to simplify the coding of some typical cases. For example, now it's easy to add and remove actions programatically from an action thanks to the new methods addActions(), removeActions(), clearActions(), setControllers(), returnToPreviousControllers() and setDefaultControllers()  present in BaseAction. Other new methods of BaseAction such as getRequest(), getContext() and getManager() add a lot of possibilities with little effort.

These are only some of the new features for developers. OpenXava 4.0 has around 90 improvements for the developers.

Download OpenXava 4.0 and try it
Published at DZone with permission of its author, Javier Paniza.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)