4.3. Framework Components

4.3.1. Code Components

Insert Component

This component generates the code for inserting a portion of text into the view.

Table 4.2. Parameters for component 'w:insert'
Name Required Explanation
value yes An OGNL expression that will be translated into java code. The evaluation result must be suitable as an argument to String.valueOf() method.

Example 4.2. Using the 'w:insert' component

	<!-- Full form -->
	<span wid="w:insert" value="ognl:book.title">book title</span>
	
	<!-- Short form -->
	<span insert="book.title">book title</span>

Error messages

Error messages are generated by the validation code generated by the framework for form input fields. Theses messages may be made visible to the user by using this component.

Table 4.3. Parameters for 'w:error' component
Name Required Explanation
field yes the field for which this error message will be displayed
message yes/no The message error. Note that if the 'key' parameter is specified this will be neglected.
key yes/no The message error key. This key corresponds to the message resource that will be loaded through the Spring application context.

Example 4.3. Using the 'w:error' component

	<!-- Form input field -->
	<input wid="name@w:input" value="ognl:person.name" valid="str:req"/>
	<!-- The error message -->
	<span wid="w:error" field="name" key="name.required" class="error">...</span>
	
	<!-- Short forms (not implemented yet) -->
	<span error="key:name.required" field="name" class="error">.../span>
	<span error="for:name" class="error">Field 'name' is required!/span> // Uninternationalized.
	

Foreach

A component that generates a for cycle over an array of objects(Object[]) or a collection (java.util.Collection)

Table 4.4. Parameters for 'w:foreach' component
Name Required Explanation
source yes The array of objects of the collection to iterate through.
value yes The object in which the current iteration object will be stored in.
index no The integer that will mark the current iteration step.

Example 4.4. Using the 'w:foreach' component

	<!-- Cycles through a list of books -->
	<!-- Full form -->
	<table>
	  <tr wid="w:foreach" source="ognl:books" value="ognl:book" index="ognl:index">
	     <td><span wid="w:insert" value="ognl:step">1<span>.</td>
	     <td><span wid="w:insert" value="ognl:book.title">Spring in Action<span></td>
	  </tr>
	</table>
	
	<!-- Short form -->
	<!-- Assumes there is a list/array named 'books' in the backing bean -->	
	<table>
	  <tr foreach="ognl:book">  
	     <td><span wid="w:insert" value="ognl:step">1<span>.</td>
	     <td><span wid="w:insert" value="ognl:book.title">Spring in Action<span></td>
	  </tr>
	</table>
	

Conditionals

supports an 'if' like conditional which may be follwed by a 'else' block.

Table 4.5. Parameters for 'w:if' component
Name Required Explanation
test yes An OGNL expression that is translated into equivalent java code. It must result into a boolean expression. This component tag and its body is rendered if the condition evaluates to 'true' at runtime.

Example 4.5. Using 'w:if' component

	<span wid="w:if" test="ognl: user != null">
  		Welcome <span wid="w:insert" value="ognl:user.name">Crisian</span>
	</span>
	
	<!-- Short form (not implemented yet!) -->
	<!-- Ognl prefix implied -->
	<span if="user != null"> Welcome ... </span>
	

An if may be followed by a single else block which renders if the 'test' condition of the if evaluates to false.

This component accepts no parameters. Note that the 'w:else' component must be preceded by a 'w:if' one and no other component should stay in between. The content between the 'w:if' and 'w:else' will be discarded.

Example 4.6. Using the w:else component

	<span wid="w:if" test="ognl: user != null">
	  Welcome <span wid="w:insert" value="ognl:user.name">Crisian</span>!
	</span>
	<span wid="w:else">Welcome guest!</span>

Messages

This component helps internationalization of application. It is built on Spring framework support for internationalization by using message source resolving through the appplication context.

Table 4.6. Parameters for 'w:if' component
Name Required Explanation
key yes The resource bundle key of the message to be inserted in the text.

Example 4.7. Using 'w:message' component

	// Full form
	<span wid="w:message" key="welcome.message">Welcome in England</span>
	
	// Short form
	<span message="welcome.message">Welcome in England</span>
	

4.3.2. Links

This component generates the code for rendering a link. A link may point to another page or invoke a listener method on the backing bean of the current page.

Table 4.7. Parameters for 'w:link' component
Name Required Explanation
action yes This argument specifies what method should be invoked on a click on this link. It should be an OGNL expression for a method call. If the page parameter is specified action is not required.
page no This argument specifies target page that will be rendered on a click on this link.

Example 4.8. Using 'w:link' component

	// Full forms
	<a wid="w:link"  page="ognl:'homePage'"> Go to your home! </a>
	<a wid="w:link"  action="ognl:edit(item)"> Edit item </a>
	
	// Short forms
	<a linkto="ognl:'homePage'"> Go to your home! </a>
	<a action="ognl:edit(item)"> Go to your home! </a>
	
	

4.3.3. Forms

Generates the code for rendering a form. Submiting a form always ends up with calling a listener method on the backing bean of the current page.

Table 4.8. Parameters for 'w:form' component
Name Required Explanation
action yes This argument specify what method should be invoked on the submit of this form. It should be an OGNL expression for a method call.

Example 4.9. Using 'w:form' component

	<form wid="w:form" action="ognl:saveTheWorld()">
		Planet Name: <input wid="w:input" value="ognl:planet" />
		<input type="submit" value="Save it now!" /> <!-- Regular submit button -->
	</form>
	
	// Short form
	<!-- Tag action attribute value must be 
			prefixed with the 'ognl:' prefix 	-->
	<form action="ognl:saveTheWorld()">