View helpers
Scooter comes with the following view helper classes. Each class has multiple static helper methods for rendering a view.
Class | Description | Examples |
---|---|---|
D | D (DateTimeHelper) class has helper methods for Date and Time. | message |
F | F (FormHelper) class has helper methods for http form. | formForOpen, formForClose |
M | M (MiscHelper) class has helper methods for all other situations. | exist, isArray, isEmpty, isset |
O | O (ObjectHelper) class has helper methods for objects including ActiveRecord related instances. | allAssociatedRecordsOf, associatedRecordOf, columnNames, columns, count, getErrorMessages, getObjectForKey, getProperty, homeInstance, hp, hv, interatorOf, property, restfulIdOf, rowInfoOf, value |
R | R (RestfulHelper) class has helper methods for routes and resources. | addResourcePath, editResourceRecordPath, resourcePath, resourceRecordPath |
T | T (TextHelper) class has helper methods for rendering a text or munipulating a string. | getDateProperty, isNumeric, pluralize, text, textOfCurrency, textOfDate, textOfNumber |
W | W (WebHelper) class has helper methods for web related request. | buttonLink, cycle, diggStylePageLinks, yahooStylePageLinks, errorMessage, get, getContextName, getContextPath, getCurrentControllerPath, getDocumentRoot, getRealPath, getURL, globale, h, htmlEscape, imageLink, imageTag, isEmpty, isEqual, isGreaterThan, isGreaterThankOrEqual, isLessThan, isLessThanOrEqual, isLOcalRequest, isPresent, label, labelLink, labelLinkForRecord, marketdown, message, nl2br, pageLink, paginationLinks, param, request, session, setDateHeader, setHeader, submitButtonLink, taggedContent, thread, value |
Why single letter for class name?
This is just a way to save some typing by programmers.
For example, which one do you prefer to use in a jsp:
//short-hand case Content: <%=W.h(aStringVariable)%> //formal case Content: <%=WebHelper.getHtmlEscapeString(aStringVariable)%>
There are 18 more keystrokes in the second case.
Detailed description of each helper method
Please refer to Java doc of a specific helper method.
Why inline method is more preferrable than JSTL?
JSTL is a fine tool. But sometimes it can be very awkward. Scooter promotes using inline methods.
For example, the following is a typical example use of JSTL:
<c:choose> <c:when test="${state == 'CA'}"> California </c:when> <c:when test="${state == 'NY'}"> New York </c:when> <c:when test="$state == 'VA'}"> Virginia </c:when> <c:otherwise> Please select a state </c:otherwise> </c:choose>
In Scooter, we like to use decode method to replace the above code:
<%=Util.decode(state, "CA=California, NY=New York, VA=Virginia", "Please select a state")%>
Other helper methods
There are many other helper methods in util package. Please refer to Java doc of a specific helper method.
Examples
WordUtilWordUtil.camelize("hello world") ==> Hello world WordUtil.camelize("active_record") ==> ActiveRecord WordUtil.pluralize("person") ==> people WordUtil.pluralize("photo") ==> photos WordUtil.underscore("Hello world") ==> hello world WordUtil.underscore("ActiveRecord") ==> active_recordT.getDateProperty
Today is <%=T.getDateProperty("weekday")%>, <%=T.getDateProperty("month")%> <%=T.getDateProperty("mday")%>, <%=T.getDateProperty("year")%> ==> Today is Thursday, October 29, 2009