You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by wolverine my <wo...@gmail.com> on 2007/04/11 09:49:31 UTC

[S2] Dispaly data in FreeMarker

I'm using Struts 2 and FreeMarker and I'm ready to move on from the
HelloWorld example...

I would like to create a page to display a list of accounts.
Hence, the following is the action class,

public class Search extends ActionSupport implements SessionAware {

    private Map session;

    public String execute() throws Exception {
        List<Account> accounts = new ArrayList<Account>();
        for (int i = 0; i < 5; i++) {
            Account account = new Account();
            account.setUserName("name" + i);
            accounts.add(account);
        }
        session.put("accounts", accounts);
        return SUCCESS;
    }

    public void setSession(Map session) {
        this.session = session;
    }
}


Subsequently the FreeMarker template can display the accounts,

<#list accounts as account>
${account.getUserName()}
</#list>


Is this the only way we push the data to FreeMarker template?

Do we need to remove the data from the session?

Can the FreeMarker template access the request parameters directly
without us adding the parameters into the session?


/Struts newbie

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] Dispaly data in FreeMarker

Posted by wolverine my <wo...@gmail.com>.
Answer to one of the questions:

> Can the FreeMarker template access the request parameters directly
> without us adding the parameters into the session?

It is described in http://struts.apache.org/2.0.6/docs/freemarker.html,

${Parameters.myParameter}


/Struts newbie

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org