Announcement Announcement Module
Collapse
No announcement yet.
Best approach in handling {provider}Connected after ConnectController?... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best approach in handling {provider}Connected after ConnectController?...

    I know there are two other posts now that are dealing with the ConnectController http://forum.springsource.org/showth...-authorization and
    http://forum.springsource.org/showth...social-samples

    but not sure if I should hijack them for this question or not even though it's somewhat related but also could just have a simple spring basics answer.

    In the ConnectController eventually connectionStatus is called which does a redirect (upon success using facebook as an example) to

    /connect/facebookConnected

    In our current app we're using some old tiles stuff but all I want to do is stuff a message into scope (Request?) such as "You are successfully connected with Facebook" and then display that message on the home page (I'll probably need a flag also to look at since I don't want to show the facebookConnect button if the user has already been connected.) What's the best approach to take to accomplish this?

    I do have an interceptor class (similar to the UserInterceptor in the samples) so I thought about handling things there?

    Right now all I have is a facebookConnected.jsp which I really don't need and is mapped via tiles as:

    Code:
    <definition name="connect/facebookConnected" path="/WEB-INF/jsp/springsocial/connect/facebookConnected.jsp"/>
    Our current app is mapped to the spring dispatchServlet based on some extensions (eg *.sdo) and I also added social/*

    What might be beneficial in our case is if the return from connectView could append a suffix, then I could map the return directly to a controller (although I think I saw a way I could map a tile definition to a custom controller as well?)

  • #2
    It sounds like you have a couple of questions here...

    First, you'd like to put some message into the request to say "You are successfully connected with Facebook". The best opportunity to do that is with a ConnectInterceptor in the postConnect() method.

    As for customizing the view chosen by connectView(), you would want to subclass ConnectController and override the connectView() method(s) to return a view you'd like them to go to. It sounds like you want them to not reference a view by its logical name, but you'd rather have them redirect to some other path. In that case you'd return something like "redirect:/someOtherPath".

    The tricky part here is that if you need your redirect to include the servlet path "/social", then there's no good way to get that from connectView() aside from hardcoding it...which, as discussed in those other threads, is not ideal. I'm reluctant to change the signature of connectView() to take the request so that you can do this...but I'll think it over while I'm working on the other issue.

    Comment


    • #3
      Originally posted by habuma View Post
      As for customizing the view chosen by connectView(), you would want to subclass ConnectController and override the connectView() method(s) to return a view you'd like them to go to.
      Since you'll be in ConnectController, connectView(String name) right now is private so that should probably be protected, there is also is the issue of it being used by the connectionStatus call without the providerId that returns connect/status. Also it'll be nice in case someone does need to overwrite connectView that it also is handed the providerId. What about maybe being slightly more verbose but allowing a bit more flexibility for end users that need to subclass ConnectController and have three methods (two of which are given the providerId as well.) The final code could look something like:

      Code:
      @RequestMapping(value="/", method=RequestMethod.GET)
      public String connectionStatus(NativeWebRequest request, Model model) {
      	setNoCache(request);
      	Map<String, List<Connection<?>>> connections = connectionRepository.findAllConnections();
      	model.addAttribute("providerIds", connectionFactoryLocator.registeredProviderIds());		
      	model.addAttribute("connectionMap", connections);
      	return statusView();
      }
      
      @RequestMapping(value="/{providerId}", method=RequestMethod.GET)
      public String connectionStatus(@PathVariable String providerId, NativeWebRequest request, Model model) {
      	processFlash(request, model);
      	List<Connection<?>> connections = connectionRepository.findConnections(providerId);
      	setNoCache(request);
      	if (connections.isEmpty()) {
      		return connectView(providerId); 
      	} else {
      		model.addAttribute("connections", connections);
      		return connectedView(providerId);			
      	}
      }
      
      protected String statusView() {
      	return getViewPath() + "status";
      }
      protected String connectView(String providerId) {
      	return getViewPath() + provider + "Connect";
      }
      protected String connectedView(String providerId) {
      	return getViewPath() + provider + "Connected";
      }

      Comment


      • #4
        Oops my apologies. When I went to edit the latest SpringSocial code from github I saw some of these new hooks were already in place! nice

        Comment


        • #5
          Just posted a reply then saw that you had beat me to the reply. Yes, those hooks are there in 1.0.0.RELEASE.

          Comment

          Working...
          X