If you don't like videos follow the instructions below.
If you are not familiar with agile development you can have a look at
agilemanifesto.org. Basically, agile development encourages the use of feedback from a working product over a careful upfront design. This gives a more prominent role to programmers and users, and minimizes the importance of analysts and software architects.
This type of development also needs a different type of tools. Because you need a working application rapidly. It must be as rapid to develop the initial application as it would be writing the functional description. Moreover, you need to respond to the user feedback quickly. The user needs to see his proposals running in short time.
OpenXava is ideal for agile development because not only does it allow a very rapid initial development, but it also allows you to make changes and see the effects instantly. Let's see a little example of this.
For example, once the user has looked at your application and starts to play with it, he takes into account that he works with books, music, software and so on. All these products have an author, and it would be useful to store the author, and see products by author.
Adding this new feature to your application is simple and rapid. First, create a new class for Author, with this:
package com.yourcompany.invoicing.model;
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;
import org.openxava.annotations.*;
import lombok.*;
@Entity @Getter @Setter
public class Author {
@Id @GeneratedValue(generator="system-uuid") @Hidden
@GenericGenerator(name="system-uuid", strategy = "uuid")
@Column(length=32)
String oid;
@Column(length=50) @Required
String name;
}
Now, add the next code to the existing Product entity:
@ManyToOne(fetch=FetchType.LAZY)
@DescriptionsList
Author author;
Thus, your Product entity has a reference to Author.
Really you have written a little amount of code. In order to see the effect, restart your application clicking on Run button:
Then go to the browser and reload the page with the
Product module, and you will see there, a combo for choosing the author of the product, just as you see here:
Adding a collection of entities
What if the user wants to choose an author and see all his products? Well. This is plain vanilla. You only have to make the relationship between Product and Author bidirectional. Go to the Author class and add the next code:
@OneToMany(mappedBy="author")
@ListProperties("number, description, price")
Collection<Product> products;
Now, restart your application and refresh the browser with
Author module. Choose an author and you will see his products. You have to see something like this:
Yes, you added a new collection, restarted your application, refreshed your browser and there you get the full user interface to manage it. In this case the user can click on Add button to choose a book from a list of all existing books or click on New to enter the data to create a new book that will be added to the collection. Moreover, the author cannot be removed while he has books associated to him. You can define another behavior with cascade as REMOVE or ALL, thus:
@OneToMany(mappedBy="author", cascade=CascadeType.REMOVE) // DON'T ADD IT TO YOUR CODE
In this way only the
New button to create new books are available, the
Add button is not present. Moreover, when the author would be removed his books will be removed too. For the author/books case we don't want this behavior, but it can be useful in many cases where the
@ElementCollection is not enough.
Summary
In this section you have the complete code and steps required to do changes and see the result in the most interactive way. You have seen how OpenXava is an agile tool, ideal for doing agile development.
Yes! Now you have a working application with little effort. Although this application "as is" can be useful as a CRUD utility or a prototype, you still need to add validations, business logic, user interface behavior and so on in order to convert these entities you have written into a business application ready for your user.
You will learn all these advanced topics in the forthcoming lessons.
Download source code of this lesson
Any problem with this lesson? Ask in the forum Everything fine? Go to Lesson 6