Log In | Sign Up   View a printable version of the current page.
  Dashboard > [fleXive] > ... > Your first fleXive application > Listing blog entries

Added by Hans Bacher, last edited by Hans Bacher on Jun 23, 2008  (view change)
Labels: 
(None)

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.

index.xhtml
<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

JSF managed HelloWorldBean's method getBlogEntries()
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;
}
Site running on a free Atlassian Confluence Open Source Project License granted to [fleXive] . Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.6.1 Build:#916 Nov 09, 2007) - Bug/feature request - Contact Administrators