Hi,
In my Grails application, I added a dependency to "spring-social" project (not the grails plugin but the actual spring-social project developed in Spring MVC). Further, I configured the beans as described in the spring social documentation.
I did NOT create Grails Controllers and instead I'm using the controllers declared in the spring-social project. However, I created GSP views so the controllers in the spring-social render those views.
Here is a summary of what I have done:
1) BuildConfig.groovy
2) under src/java, created "com.splitpen.social.config.SocialConfig.java" that contains bean configurations as described in the spring social documentation and samplesCode:dependencies { def springSocialVersion = "1.0.2.RELEASE" def springSocialFacebookVersion = "1.0.1.RELEASE" // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg. compile "org.springframework.social:spring-social-core:${springSocialVersion}" compile "org.springframework.social:spring-social-web:${springSocialVersion}" compile "org.springframework.social:spring-social-facebook:${springSocialFacebookVersion}" compile "org.springframework.security:spring-security-crypto:3.1.0.RC3" }
3) config.groovy, I pointed to the config package so Grails can scan the bean configuration
I omitted some customization I did such as user domain class and related DAOs, but long story short I got it working with a caveat.Code:// packages to include in Spring bean scanning grails.spring.bean.packages = ["com.splitpen.social.config"]
In the GSP file, I had to add ".dispatch" suffix to the post URL like this
If I omit the ".dispatch" suffix, I get 404 error. I also found that if I omit the suffix in the view but add a URL mapping, it also works:Code:<form name="fb_signin" id="fb_signin" action="signin/facebook.dispatch" method="POST"> <input type="hidden" name="scope" value="email,publish_stream,user_photos,offline_access" /> <button type="submit" class="connectButton">Facebook</button> </form>
I'm not happy with either workaround:Code:UrlMappings.groovy "/signin/facebook"(uri:"/signin/facebook.dispatch")
1) I don't like adding the "dispatch" suffix in view because I don't have to do that when I use Grails Controller. So whoever implements the view now needs to know that the controller is either implemented in Grails or Spring MVC.
2) I don't like adding the URL Mapping either because I couldn't figure out how to use wildcards so I wouldn't have to add a mapping for every URL combination. Specifically I tried to do something like this with no success
Otherwise I have to add a mapping for every action that is handled by signin controller that is declared in Spring MVC.Code:"signin/**.dispatch"(uri:"signin/**")
I'm looking for some guidance and suggestions on either how to better integrate existing Spring MVC controllers into Grails so that I don't have to use the suffix or a convenient way to the URL mapping as I described above.
Thanks,
Ali


Reply With Quote
