Managing Domain Objects
One of Riot's core features is its ability to manage domain objects. To illustrate this feature we'll stick to the Spring Petclinic example and create a UI to manage the vets working in the clinic. All this will be done without writing a single line of Java code.
Defining a List
First of all, we'll define a list view to browse the vets. We therefore add the following to lists.xml file which is located in the WEB-INF/riot-config directory:
<dao ref="hqlDao">
<property name="entityClass" value="org.springframework.samples.petclinic.Vet" />
</dao>
<columns>
<column property="firstName" />
<column property="lastName" />
<command id="edit" />
<command id="delete" />
</columns>
<command id="add" />
</list>
This gives us a list that displays the vet's first and last name and has buttons for each entry that allow us to to edit or to delete a record. Additionally there's a button at the bottom of the list which can be used to create new entries:
The XML from above uses a hqlDao which is actually a Spring managed prototype bean that is provided by the riot-hibernate module:
<property name="sessionFactory" ref="sessionFactory" />
</bean>
Alternatively we could implement our own RiotDao or use a CustomDaoAdapter to utilize an existing DAO (like one of the Clinic implementations).
Adding a Form
The next thing we need is a form to edit vets. What we have to do is to add an entry to forms.xml which is located in the same directory:
<textfield bind="firstName" required="true" max-length="255" />
<textfield bind="lastName" required="true" max-length="255" />
<checkbox-group bind="specialtiesInternal" label-property="name">
<model ref="hqlOptionsModel">
<set-property name="hql" value="from Specialty" />
</model>
</checkbox-group>
</form>
This will create a simple form which looks like this:
We have to use the protected property specialtiesInternal instead of specialties, because Vet.getSpecialties() returns an unmodifiable list.
Linking it together
There is one thing left to do: We have to link the form to the list definition. This might look a little bit cumbersome at the first sight, but there's a good reason for doing so. Lists and forms can be arranged in a hierarchical way, which means that a form can have a set of nested lists, which in turn can have forms which have lists and so on. This way it's possible to navigate through deeply nested object graphs.
In order to complete our example we have to add the following to the editors.xml file:
<form form-ref="vet" />
</list>