Difference between revisions of "Xebra Write Xeb File"

(Command Links)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Xebra]]
 
[[Category:Xebra]]
 +
[[Xebra About|About]] | [[Xebra Installation|Installation]] |  [[Xebra Documentation|Documentation]] |  [[Xebra Tutorial|Tutorials]] | [[Xebra FAQ|Frequently Asked Questions]]
 +
  
 
=Hello World=
 
=Hello World=
  
The simlest xeb file is a hello world example:
+
The simplest xeb file is a hello world example:
  
 
<xml>
 
<xml>
Line 16: Line 18:
  
 
<xml>
 
<xml>
<xeb:iterate list="persons" variable="person" class="PERSON">
+
<xeb:iterate list="persons" variable="person" type="PERSON">
 
<xeb:display feature="#{person.name}" />
 
<xeb:display feature="#{person.name}" />
 
</xeb>
 
</xeb>
Line 27: Line 29:
  
 
<xml>
 
<xml>
<f:form variable="new_person" class="PERSON">
+
<f:form variable="new_person" type="PERSON">
 
<f:input_text value="name" name="a_name" text="#{new_person.name}" />
 
<f:input_text value="name" name="a_name" text="#{new_person.name}" />
 
<f:button value="Save" action="save"/>
 
<f:button value="Save" action="save"/>
Line 53: Line 55:
  
 
<xml>
 
<xml>
<xeb:iterate list="persons" variable="person" class="PERSON">
+
<xeb:iterate list="persons" variable="person" type="PERSON">
 
<f:form>
 
<f:form>
<f:command_link label="#{person.name}" action="delete" variable="person" /> </ br>
+
<f:command_link label="#{person.name}" action="delete" variable="person" /> <br />
 
</f:form>
 
</f:form>
 
</xeb:iterate>
 
</xeb:iterate>

Latest revision as of 13:39, 31 August 2009

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}" />
</xeb>

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"/>
</f:form>

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:input>
<f:validation_result name="a_name" />
<f:button value="Save" action="save"/>
</f:form>

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:form>
<f:command_link label="#{person.name}" action="delete" variable="person" /> <br />
</f:form>
</xeb:iterate>

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).