Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How could I pass JSF form data to a Spring controller?

 
Jochen Szostek
Ranch Hand
Posts: 42
Android Google Web Toolkit Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bonjour,

I'm working on a Spring based web application with a JSF front-end.

By using JSF only I can easily put my form date in a JSF bean with syntax like:


I also mananged to make my Spring beans available in JSF so I can already use Spring Beans in a JSF context.

But to process my data when using just JSF I would use a method in in the class I've put the data in. By doing something like:


Now I would like this form data to be handled by Spring instead of JSF, via a Spring controller for example. But since I'm quite new with all these technologies I wouldn't have an idea on how I could map my JSF (form) action together with the form data to a Spring controller, for further processing.

Could anyone here please give me some pointers on how I could arrange this? Or I'd be also very happy if someone could tell me where I could find this information. (While googling I couldn't find the answer, and I already have the Spring in action book but the JSF chapter doesn't give any info on this)

All help appreciated a lot!

Have a nice day and kind regards,

Jochen
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By definition, you're using JSF regardless, since you'd specifying the action in a JSF tag!

When you use the Spring/JSF interconnect, the Spring beans can be referenced for injection into JSF managed beans. I don't know if that also puts them in scope for JSF page variable references or not, however. I suspect it does.

However, I'm not sure I'd recommend it. It's tying what's basically a business-layer object straight to the view, short-circuiting the usual tier layering. More likely, I'd make a JSF facade backing bean and let it pass the action request on. If for no other reason than that JSF actions are constrained to a certain format (accepts void/returns String), even though JSF backing beans are POJOs.
 
Jochen Szostek
Ranch Hand
Posts: 42
Android Google Web Toolkit Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tim Holloway:
By definition, you're using JSF regardless, since you'd specifying the action in a JSF tag!


Well it's just that I want to use JSF to create my whole view including forms. I head about Facelets becoming very popular and I thought it would be a good choice; so I can download some web components when further expanding this project during the next couple of years. And I thought of combining this kind JSF/facelets view with a Spring framework (model and controller).

I thought it would be best of defining the action in a JSF tag and pass it on to Spring somehow. I must admit I'm quite new to Spring and JSF, I only got some quite basic examples running of them two separately, and now I would like to try to combine them somehow.


When you use the Spring/JSF interconnect, the Spring beans can be referenced for injection into JSF managed beans. I don't know if that also puts them in scope for JSF page variable references or not, however. I suspect it does.


Yes it does indeed. In my first step now trying to combine JSF and Spring, I've made a user registration form in JSF that uses my Spring user bean to access my user object.


However, I'm not sure I'd recommend it. It's tying what's basically a business-layer object straight to the view, short-circuiting the usual tier layering.


Hmmm...very good point you make here. But I only thought of using this method for displaying my business objects because it doesn't add much overhead + I don't know if other methods might allow me to "easily" add Facelet functionality later on. In the other direction (view to model) I had in mind going via the Spring controller.

More likely, I'd make a JSF facade backing bean and let it pass the action request on. If for no other reason than that JSF actions are constrained to a certain format (accepts void/returns String), even though JSF backing beans are POJOs.


Could you please explain what you mean by "JSF facade backing bean"? (or if you could tell me where I could find some more info about this? I don't mind buying some books to make things more clear for me either)
EDIT: I just bought "JSF in action", it has a topic on backing beans so I will be able to comprehend it soon.

Thanks again a whole lot for your reply. It's not easy seeing how all these new technologies (for me, that is ) can work together.

Kind regards,

Jochen

[ July 18, 2008: Message edited by: Jochen Szostek ]
[ July 18, 2008: Message edited by: Jochen Szostek ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic