This file explains how does VRaptor iteract with the presentation layer and how it makes things so easy to switch between different presentation engines like JSP, Velocity and Freemarker for example.
Outjection is used to put objects in some scopes.
VRaptor supports outjection to the Action, Request (default) and Session scope.
Action scope is similar to the PageScope in the JSP and Servlet specification, while request and session scope are exactly what their name means. See ScopeType.
A simple search that outjects its result to the request:
@Component("users") public class LoginLogic { private List<User> users; private String name; // alias this method name to "search" @Logic("search") public void searchUsers(String name) { // weird dao, but ok for this example this.users = new UserDao().searchByName(name); } public List<User> getUsers() { return this.users; } }
Here we use the getter getUsers() for outjection to the request scope.
In the above example, the following code is executed:
request.setAttribute("users", users);
Instead of the getter you can also use the @Out anotation.
@Out private List<User> users;
This outjects the users to the request.
Please observe, that when you use the @Out anotation no getter is required.
If you would like to change the scope to which the attribute is outjected, simply use:
@Out(scope=ScopeType.SESSION) private List<User> users;
Here we eject the users to the session scope.
Use:
@Out(scope=ScopeType.SESSION, key="USERS") private List<User> users;
when you want to eject the users to the session scope with the key USERS.
This executes the following code:
session.setAttribute("USERS", users);
Assuming we have used the key users, if you simply want to toString your object:
<html> Here is the list.toString: ${users}... If I wanted, I could do a forEach in this collection... </html>