Views

Views are used to present information to the user. In EasyWeb4J applications, views are created using normal JSP files. You can utilize the JSTL and standard JSP actions to perform most presentation tasks. EasyWeb4J does provide a bunch of its own tags for simplifying view creation. You are not required to use them but using them can make your life a lot easier.

All views for controllers' actions live in /WEB-INF/views/ControllerName/action.jsp.

EasyWeb4J Attributes

EasyWeb4J sets a few attributes to facilitate creation of views. These can be used in EL Expressions within JSP pages. Their scope and purpose are as below.

Attribute Scope Purpose
contextRoot Request Provides the context root of the web application. It can be used to fetch
resources such as style sheets, scripts and images from web application's
root directory. Example: "/languages"
view Request The actual view which needs to be rendered within the layout. Can be used
in layout pages to insert the actual content for the action.
flash Session A map of flash messages.

EasyWeb4J Tag Library

EasyWeb4J provides a bunch of custom tags to simplify creation of views. The tag library can be used in JSP pages with the taglib directive as below,

<%@taglib uri="http://easyweb4j.sourceforge.net/easyweb4j" prefix="e" %>

An important characteristic of EasyWeb4J tags is that all of them accept dynamic attributes. Any attribute other than the ones specified here are directly passed into the corresponding HTML tag generated. Hence you can use all of you favorite HTML attributes with EasyWeb4J tags. The various tags provided and their attributes are as below.

Tag Attributes
<e:postLink> Behaves like HTML <a> tag. However, sends a POST request to the href URL
instead of GET.
 
href - Similar to href in <a>.
target - Similar to target in <a>.
<e:collectionSelect> Generates a HTML <select> tag from a collection of objects.
 
items - A collection of objects which should be listed.
valueProperty - The property of objects in the collection to be used for
option elements' "value" attribute. If not specified,
toString() is invoked on each item is used.
labelProperty - The property of objects in the collection to be used for
option elements' content. If not specified, toString()
is invoked on each item is used.
currentValue - Item(s) of the same type as the objects in items
representing the currently selected value(s).
prompt - Text to be displayed for an empty first item. No empty
item is created if no prompt is specified.
<e:booleanCheckBox> Generates a HTML "checkbox" input, representing a boolean state. HTML pages
do not send any request parameter if no check box is selected. This tag
includes a hidden field to work around this.
 
state - Default state of the checkbox.
name - Similar to name in <input>.
<e:checkBox> Generates a plain HTML "checkbox" input.
 
state - Default state of the checkbox button.
<e:radioButton> Generates a plain HTML "radio" input.
 
state - Default state of the radio button.
<e:dateTime> Generates a HTML text input for accepting date/time input. Also includes a
hidden field to store the date/time format.
 
value - The default date/time value.
name - Similar to name in <input>.
hideField - Generates 2 hidden inputs instead of the text input.
Useful when you want to use JS instead of plain text.
format - Date format as in SimpleDateFormat.
<e:message> Retrieves the localized value for the given key. Follows the behavior of
<fmt:message> while resolving the LocalizationContext to use. However, it
doesn't support the parent <fmt:bundle> tag yet.
 
key - Message key to be looked up.
bundle - Localization context in whose resource bundle the message
key is looked up. .

Layouts

Layouts in EasyWeb4J are templates for your views. All JSP files used for layouts are in the /WEB-INF/layouts directory. Layout for the application is available in /WEB-INF/layouts/Application.jsp.

The view request attribute can be used in the layout files to include the contents of the current action's view.

Message Bundles

EasyWeb4J mostly re-uses the message bundle capabilities of JSPs. The localized messages for errors and flashes be specified in a resource bundle and then fetched using the <e:message> tag. <fmt:message> can also be used but <e:message> handles null or empty keys better.

EasyWeb4J creates projects with a default message bundle src/main/resources/messages.properties. It also sets up this bundle in /WEB-INF/layouts/Application.jsp, using <fmt:setBundle>.