Dashboard > Stripes > ... > Beginning Stripes > Sample Application
Stripes Log In   View a printable version of the current page.
Sample Application
Added by Tim Fennell, last edited by Tim Fennell on Jul 21, 2006  (view change)

Stripes has moved! This site is no longer being actively maintained. Please point your browsers at http://www.stripesframework.org and update your bookmarks. Thank you.

A standalone sample application called Bugzooky is included in the Stripes Download. Browsing the source code and JSPs for the application is one of the best ways to get to grips with some of the more advanced features of Stripes.

The Bugzooky sample application has examples of how to use the following features (among others):

  • Indexed properties (aka multi-row forms)
  • File upload
  • Streaming data back to the client for download
  • Built in and custom validation
  • Multiple events from a single form
  • Re-using the same pages and ActionBeans for add flows and edit flows

The Stripes Download includes a pre-built war file that includes the example application, as well as the source for the example. A few screen shots and an example class and JSP follow to whet your appetite.

Bugzooky Screen Shots
(view as slideshow)
     
  A screen shot of Bugzooky's bulk edit page with errors.   A screen shot of Bugzooky's add bug page with errors.
 
     
  A screen shot of Bugzooky's bug list page.   A screen shot of Bugzooky's bulk edit page.
 

"BulkAddEditBugs.jsp"
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp" %>


<div class="sectionTitle">Bulk Add</div>

<jsp:useBean id="componentManager" scope="page"
             class="net.sourceforge.stripes.examples.bugzooky.biz.ComponentManager"/>
<jsp:useBean id="personManager" scope="page"
             class="net.sourceforge.stripes.examples.bugzooky.biz.PersonManager"/>

<stripes:form action="/bugzooky/MultiBug.action">
    <stripes:errors/>

    <table class="display">
        <tr>
            <th>ID</th>
            <th>Component</th>
            <th>Assignee</th>
            <th>Priority</th>
            <th>Status</th>
            <th>Short Description</th>
            <th>Long Description:</th>
        </tr>

        <c:choose>
            <c:when test="${actionBean != null}">
                <c:set var="list" value="${actionBean.bugs}" scope="page"/>
            </c:when>
            <c:otherwise>
                <c:set var="list" value="<%= new Object[5] %>" scope="page"/>
            </c:otherwise>
        </c:choose>

        <c:forEach items="${list}" var="bug" varStatus="loop">
            <tr>
                <td>
                    ${bug.id}
                    <stripes:hidden name="bugs[${loop.index}].id"/>
                </td>
                <td>
                    <stripes:select name="bugs[${loop.index}].component.id">
                        <stripes:option value="">Select One</stripes:option>
                        <stripes:options-collection collection="${componentManager.allComponents}"
                                                    label="name" value="id"/>
                    </stripes:select>
                </td>
                <td>
                    <stripes:select name="bugs[${loop.index}].owner.id">
                        <stripes:option value="">Select One</stripes:option>
                        <stripes:options-collection collection="${personManager.allPeople}"
                                                    label="username" value="id"/>
                    </stripes:select>
                </td>
                <td>
                    <stripes:select name="bugs[${loop.index}].priority">
                        <stripes:option value="">Select One</stripes:option>
                        <stripes:options-enumeration enum="net.sourceforge.stripes.examples.bugzooky.biz.Priority"/>
                    </stripes:select>
                </td>
                <td>
                    <stripes:select name="bugs[${loop.index}].status">
                        <stripes:option value="">Select One</stripes:option>
                        <stripes:options-enumeration enum="net.sourceforge.stripes.examples.bugzooky.biz.Status"/>
                    </stripes:select>
                </td>
                <td><stripes:textarea cols="25" rows="3" name="bugs[${loop.index}].shortDescription"/></td>
                <td><stripes:textarea cols="25" rows="3" name="bugs[${loop.index}].longDescription"/></td>
            </tr>
        </c:forEach>
    </table>

    <div class="buttons">
        <stripes:submit name="SaveOrUpdate" value="Save"/>
    </div>
</stripes:form>
<%@ include file="footer.jsp" %>
MultiBugActionBean.java
@UrlBinding("/bugzooky/MultiBug.action")
public class MultiBugActionBean extends BugzookyActionBean {
    /** Populated during bulk add/edit operations. */
    private List<Bug> bugs = new ArrayList<Bug>();

    /** Populated by the form submit on the way into bulk edit. */
    private int[] bugIds;

    /** Gets the array of bug IDs the user selected for edit. */
    public int[] getBugIds() { return bugIds; }

    /** Sets the array of bug IDs the user selected for edit. */
    public void setBugIds(int[] bugIds) { this.bugIds = bugIds; }

    @ValidateNestedProperties({
        @Validate(field="shortDescription", required=true, maxlength=75),
        @Validate(field="longDescription", required=true, minlength=25),
        @Validate(field="component.id", required=true),
        @Validate(field="owner.id", required=true),
        @Validate(field="status", required=true),
        @Validate(field="priority", required=true)
    })
    public List<Bug> getBugs() {
        return bugs;
    }

    public void setBugs(List<Bug> bugs) {
        this.bugs = bugs;
    }

    @DefaultHandler
    @HandlesEvent("SaveOrUpdate")
    public Resolution saveOrUpdate() {
        BugManager bm = new BugManager();
        PersonManager pm = new PersonManager();
        ComponentManager cm = new ComponentManager();

        for (Bug bug : bugs) {
            Bug newBug = populateBug(bug);
            bm.saveOrUpdate(newBug);
        }

        return new ForwardResolution("/bugzooky/BugList.jsp");
    }

    @DontValidate
    @HandlesEvent("PreEdit")
    public Resolution preBulkEdit() {
        // If the user didn't select any bugs to edit, bad user.
        if (this.bugIds == null || this.bugIds.length < 1) {            
            ValidationErrors errors = new ValidationErrors();
            errors.add( new SimpleError("You must select at least one bug to edit.") );
            getContext().setValidationErrors(errors);
            return getContext().getSourcePageResolution();
        }

        BugManager bm = new BugManager();
        for (int id : this.bugIds) {
            this.bugs.add( bm.getBug(id) );
        }

        return new ForwardResolution("/bugzooky/BulkAddEditBugs.jsp");
    }
}

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.7 Build:#524 Jul 28, 2006) - Bug/feature request - Contact Administrators