Difference between revisions of "Xebra Write Xeb File"

(New page: =Hello World= The simlest xeb file is a hello world example: <xml> Hello World! </xml> This page will just display "Hello World!" as is. =Iteration over lists and display= If we have ...)
 
(Command Links)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
[[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 14: 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>
 
</xml>
 
</xml>
  
 
+
Notice the that the feature attribute is special. Attributes with "#{}" denote variable attributes and use defined variables (here the person from iterate).
  
 
=Wrapped forms=
 
=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").
 +
 +
<xml>
 +
<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>
 +
</xml>
 +
 +
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.
 +
 +
<xml>
 +
<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>
 +
</xml>
 +
 +
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.
 +
 +
<xml>
 +
<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>
 +
</xml>
 +
 +
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).

Latest revision as of 12: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).