Listing blog entries
On this page already submitted blog entries can be viewed. This page is build with XHTML and JSF tags explained as follows.
<h:outputLink value="create.xhtml">Create a new entry</h:outputLink>
<!-- Render available blog postings, as returned by helloWorldBean.blogEntries -->
<!-- The Facelets ui:repeat tag is used to iterate over arrays, lists and JSF datamodels -->
<ui:repeat value="#{helloWorldBean.blogEntries}" var="column"> <!-- (1) -->
<h3>
<!-- Entry title. Access the value of each column through the expression language
and the column index -->
#{column[1]}
</h3>
<pre>#{column[2]} <!-- Entry text -->
<i>#{column[3]}</i> <!-- Creation date -->
</pre>
</ui:repeat>
(1) To iterate over the list of submitted announcements Facelet's
<ui:repeat/> tag is used. The list is wrapped by a javax.faces.model.DataModel returned by the JSF managed HelloWorldBean's method getBlogEntries().
A row of the datamodel provides indexed access to the columns selected in the search query. In this case, #{column[0]} would be the content primary key (@pk), #{column[1]} returns the entry title, and so on.
JSF managed HelloWorldBean
public DataModel getBlogEntries() throws FxApplicationException {
if (blogEntries == null) {
final FxResultSet result = new SqlQueryBuilder()
.select("@pk", "entryTitle", "entryText", "created_at")
.type("blogEntry")
.orderBy("created_at", SortDirection.DESCENDING)
.getResult();
blogEntries = new FxResultSetDataModel(result);
}
return blogEntries;
}