This is possibly OT, but since I'm working on in the context of SpringSocial figured I'd try to get some help here first.
In the Spring Social Showcase you have a ConnectedToHandlerInterceptor that looks like on every request will check to see if you if you have connections for facebook and twitter.
The majority of the time I'd think you'd need to know this only on the front-end and typically on only certain pages ( eg maybe on the main page you want to show the "connect with facebook" button if you haven't done so, but this only appears on one page.)
I'm using Spring 3.0.6 and when creating a tag for this so that the ConnectionRepository could be injected has been proving difficult.
I end up with an error on startup:
I tried adding RequestContextListener to web.xml but that didn't seem to help. Is it going to be too difficult to create a Tag to do what I want, or am I just missing something simple?Code:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.connectionRepository': Scope ' request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an a ctual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request an d still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContext Listener or RequestContextFilter to expose the current request.
Here is what I'm currently attempting:
bean declaration:
tag: (note: not my idea to use java.util.logging...sadly the project is already entrenched with itCode:<bean class="com.foocompany.web.taglib.social.SocialConnectedTag"> <property name="connectionRepository" ref="connectionRepository"/> </bean>
Sample usage (tld exists just not showing it.)Code:@Configurable public class SocialConnectedTag extends SimpleTagSupport { private final static Logger logger = Logger.getLogger(SocialConnectedTag.class.getName()); //tag attribute private String provider; //set from spring private ConnectionRepository connectionRepository; @Override public void doTag() throws JspException, IOException { if (!provider.equals("facebook") && !provider.equals("twitter")) { logger.severe("Provider: "+provider+" passed to SocialConnectedTag and is not a valid provider"); return; } if (connectionRepository.findConnections(provider).size() > 0) { StringWriter sw = new StringWriter(); getJspBody().invoke(sw); JspWriter out = getJspContext().getOut(); out.println(sw.toString()); } } public void setProvider(String provider) { this.provider = provider; } public void setConnectionRepository(ConnectionRepository connectionRepository) { this.connectionRepository = connectionRepository; } }
Code:<social:connected provider="facebook">You're connected to facebook</social:connected>



Reply With Quote