You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe just I don't know it, I can't find a way to inject a session scoped
instance with specified name (session attribute name). Thus I can't use the
instance on my jsp page, for example, sessionScope.<myAttributName>.value.
Or that's not the way the thing should go?
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.
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!).
From kevin.wang.kp on April 28, 2007 01:49:37
Maybe just I don't know it, I can't find a way to inject a session scoped
instance with specified name (session attribute name). Thus I can't use the
instance on my jsp page, for example, sessionScope.<myAttributName>.value.
Or that's not the way the thing should go?
Original issue: http://code.google.com/p/google-guice/issues/detail?id=97
The text was updated successfully, but these errors were encountered: