Xebra Write Xeb File

About | Installation | Documentation | Tutorials | Frequently Asked Questions

Hello World

The simplest xeb file is a hello world example:

Hello World!

This page will just display "Hello World!" as is.

Iteration over lists and display

If we have a list and want to iterate over it, we can simply use the iterate tag.

<xeb:iterate list="persons" variable="person" type="PERSON">
<xeb:display feature="#{person.name}" />

Notice the that the feature attribute is special. Attributes with "#{}" denote variable attributes and use defined variables (here the person from iterate).

Wrapped forms

HTML forms have their managed counterpart in XEBRA. If we want to retrieve all the data from a form automatically, we can use the Form tag library ("f").

<f:form variable="new_person" type="PERSON">
<f:input_text value="name" name="a_name" text="#{new_person.name}" />
<f:button value="Save" action="save"/>

This will generate a page with a form, a text field and a button. On a click on the button a new object of type PERSON is created and the name is set to the value in the text field. Most of the time we want to validate inputs from forms. With validators we can check if an input is valid.

<f:form variable="new_person" class="PERSON">
<f:input_text value="name" name="a_name" text="#{new_person.name}" >
<f:validator class="NOT_EMPTY_VALIDATOR" />
<f:validator class="PERSON_NAME_VALIDATOR" />
<f:validation_result name="a_name" />
<f:button value="Save" action="save"/>

To validate the input field we simply added two validators to the desired input field. Now if the validators report an invalid input the save action is not executed and errors messages are stored into a list. They can be displayed with a validation_result tag, by using the same identifier as the input_text ("a_name")

Command Links

In Xebra actions can not only be assigned to buttons but to links as well. For instance it can be used to delete items from a list.

<xeb:iterate list="persons" variable="person" type="PERSON">
<f:command_link label="#{person.name}" action="delete" variable="person" /> <br />

This will result in a page with the list of all person's names as links. If you click the link the person will be deleted (via the delete feature of the controller specified with the action argument in the command_link tag).