Open GoogleCodeExporter opened 9 years ago
The session scoped instance is stored under the name obtained by converting the
"Key"
to a string.
For an injected field of type "com.example.Service" and no annotation, this
will look
something like "Key[type=com.example.Service, annotation=[none]]"
Within your JSP page you can then use:
<c:set var="serivceRef" value="${sessionScope['Key[type=com.example.Service,
annotation=[none]]']}"/>
Of course, it would be nice to check if the key includes the
'com.google.inject.name.Named' annotation, and then just use the name as the
session
attribute name.
Otherwise you can always create your own custom scope (based on
com.google.inject.servlet.ServletScopes) to do this.
Original comment by tonyand...@gmail.com
on 14 Jan 2008 at 12:38
Usually you should use @SessionScoped so I don't need to interact with the
HttpSession directly. To do so,
create a binding like this one in your module:
bind(MyService.class).toProvider(new Provider<MyService>() {
@Inject HttpSession session;
public MyService get() {
return (MyService) session.getAttribute("myService");
}
});
Guice's built-in support is preferred since it provides more type safety (no
casts!).
Original comment by limpbizkit
on 31 May 2008 at 7:16
Original issue reported on code.google.com by
kevin.wa...@gmail.com
on 28 Apr 2007 at 5:49