View Javadoc

1   package org.appfuse.webapp.services.impl;
2   
3   import org.apache.tapestry5.ValueEncoder;
4   import org.appfuse.model.Role;
5   import org.appfuse.service.RoleManager;
6   
7   
8   public class RoleEncoder implements ValueEncoder<Role> {
9   
10      private RoleManager roleManager;
11  
12      public RoleEncoder(RoleManager roleManager) {
13          this.roleManager = roleManager;
14      }
15  
16      public String toClient(Role value) {
17          return String.valueOf(value.getId());
18      }
19  
20      public Role toValue(String clientValue) {
21          // happens when testing with iBatis for some reason
22          if ("null".equals(clientValue)) {
23              return null;
24          }
25  
26          Long id = Long.valueOf(clientValue);
27          return roleManager.get(id);
28      }
29  
30  }