Look, what have you done?

Since only creating events may become a little boring over the long run, we will need to add some more actions and templates to work with them. I'll present you the needed work on the following pages, including source code. The code we show contains only the most impotant stuff, but you can download the complete source code for the third chapter.

Listing events

First, we need a list of the created events. Since the list may become huge, we are going to show it on a separate page.
To call the list, we'll add a tab to the tabbedPane we created on the user details page web/user/view.ftl

<@show.tab name="event.list"
  url="${base}/event/list.action?author=${user.id?c}"
  newPage=true
  separator="" />

For the list of events only very little code is needed on the template. Just place the content below in a file called web/event/list.ftl

<@show.page title="All Events" >
   <@show.collection elements=events title="Events" ; event >
      <@show.link obj=event label=event.title />
   </@show.collection>
</@show.page>


Template result showing two events. You will have to finish this tutorial page before being able to this screen

Querying objects in Tiny Marbles.

The only thing the action must do is to fetch the collection of events. Since there's no direct mapping from "User" to "Event", we will use a Marbles Filter that says "give me the events for which the author is X". Like several operations in Tiny Marbles, querying is done with a chain of method calls:

getRepository().createFilter("Event")
  .eq("author", author)
  .list();

Without getters and setters, the action comes down to almost one (very important) line:


public class ListEvent extends BasicAction {
    private Collection events;
    private PObject author;
    public ListEvent(Repository repository, Talos talos) {
        super(repository, talos);
    }
    @Override
    public String execute() throws Exception {
        events = getRepository().createFilter("Event").eq("author", author)
      .list();
        return SUCCESS;
    }
    @Override
    public boolean authorize(String subject) throws EntityNotFoundException,
      TalosHibernateException {
        return true;
    }
    public boolean isValid() {
        if(isNull(author)){
            addFieldError("author","cannot be empty");
            return false;
        }
        return true;
    }
    public Collection getEvents() {
        return events;
    }
    public void setAuthor(PObject author) {
        this.author = author;
    }

We did impress Joey with this one and hope you are impressed too.

XWork declaration
Same old story. Did you notice that we name the templates after the action names?

<action name="list" class="org.mumtutorial.action.event.ListEvents">
   <result>list.ftl</result>
   <result name="input" type="chain">error</result>
</action>

I18N

For listing events label, add to config/mum_messages.properties:

tab.event.list=List events

Please send us comments, questions, criticism:

Please send us comments, questions, criticism!