MyMobileWeb - JSTL Integration
From Morfeo Wiki
Contents |
Introduction
JSTL library is a component of Java 2 Entreprse Edition (J2EE) specification. It's managed by Sun MicroSystems. JSTL is a set of tags and stantdar libraries which are a framework for Java Server Pages (jsps) development. JSTL tags are distributed in 4 libraries:
- core: it contains functions for flow management, assignment values and other utilities.
- XML: it contains functions for XML processing.
- fmt: it contains functions for multi-language platform, money and date format.
- sql: it contains functions for database access.
Configuration
In order to use JSTL tags in the mymw presentations, the next steps must be followed:
- Copy jstl.jar and standard.jar JSTL libraries in the folder WEB-INF/lib from the web application.
- Specify the namespace in the document tag, in presentations where JSTL will be used.
<mymw:document xmlns:mymw="http://morfeo-project.org/mymobileweb" xmlns:c="http://java.sun.com/jsp/jstl/core" id="query">
MyMobileWeb – JSTL integration
MyMobileWeb has added a subset of JSTL tags to its language. This is a subset of the tags defined in the core library.
These added tags are explained below.
<if> tag
Simple condition tag.
Description
The evaluation of the condition sets if the 'if' tag body must be processed or not.
Attributes
- test (required): E.L. containing the condition
- var: Variable name where the result of evaluate the condition will be saved. It’s a boolean type.
- scope: Variable scope. Default value: request.
Content
- If the parent is a body tag, it can contain the same childs that its parent.
- If the parent is a panel tag, it can contain the same childs that its parent.
- If the parent is a div tag, it can contain the same childs that its parent.
Example
<c:if test="${total == 1}" >
<mymw:label>Congratulations!! You are the first</mymw:label>
</c:if>
<forEach> tag
Simple iteration tag.
Description
Simple iteration which accepts several kinds of collections for iterating over them.
Attributes
- items: Collection of elements that will be iterated.
- begin: If items attribute is defined the iteration begins at 0 index. If it’s not defined the iteration begins in the index showed in this attribute.
- end: If items attribute is specified, the iteration ends at the index showed by end attribute. If items is not specified the iteration ends when the last item will be iterated.
- step: Iteration step.
- var: Var name that stores the actual element in the iteration.
- varStatus: Var name that stores the state of the iteration.
Content
- If the parent is a body tag, it can contain the same childs that its parent.
- If the parent is a panel tag, it can contain the same childs that its parent.
- If the parent is a div tag, it can contain the same childs that its parent.
Example
When this structure is used for iterating and there are controls with an id required attribute, the varStatus attribute of the forEach must be specified:
<c:forEach var="x" varStatus="status" begin="0" end="5" step="1">
<mymw:entryfield id="name" bind="${myVar.${status}}" class="name" />
</c:forEach>
In this example, the identifiers of the entryfields will be name_0, name_1, ...
<choose> tag
Condicional tag.
Description
Simple condition tag that shows a mutual exclusion stablished by when and otherwise tags.
Attributes
It has no attributes
Content
Contains the next child tags and in this order:
- <when> 1 or more times
- <otherwhise> only one time
Example
<c:choose>
<c:when test="${item.type == 'image/gif'}">
<mymw:label>It's gif</mymw:label>
</c:when>
<c:when test="${item.type == 'image/jpeg'}">
<mymw:label>It's jpeg</mymw:label>
</c:when>
<c:otherwise>
<mymw:label>Unknown format</mymw:label>
</c:otherwise>
</c:choose>
<when> tag
Condicional tag.
Description
Choose child tag, its body is processed when the evaluation of its condition is true.
Attributes
- test (required): E.L. with the condition.
Content
- If the parent is a body tag, it can contain the same childs that its parent.
- If the parent is a panel tag, it can contain the same childs that its parent.
- If the parent is a div tag, it can contain the same childs that its parent.
Example
See choose example.
<otherwise> tag
Condicional tag.
Description
Choose child tag, this is the next tag to the when ones, its body will be procesed if all the previous conditions have failed.
Attributes
It has no attributes.
Content
- If the parent is a body tag, it can contain the same childs that its parent.
- If the parent is a panel tag, it can contain the same childs that its parent.
- If the parent is a div tag, it can contain the same childs that its parent.
Example
See choose example.
<set> tag
Assigment values tag.
Description
This tag assigns the result of the expression evaluation to a variable or an object property.
Attributes
- var: Var name which will store the value.
- value: E.L. to be evaluated.
- target: Object which property will be assigned. It can be a JavaBean or a java.util.Map
- scope: Variable scope. Default is request.
- property: Object defined in 'target' attribute property.
Content
It has no child tags.
Example
<c:set var="number">1</c:set>
<remove> tag
Tag for deleting.
Description
If the scope is specified, it deletes a var from that scope.
Attributes
- var: Var name to be deleted.
- scope: Variable scope. Default is request.
Content
It has no child tags.
Example
<c:remove var="number"/>
