Forums Register Login

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

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 ]
I have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 5369 times.
Similar Threads
how to tell MultiActionController Command Object is Of type com.dss.ems.model.User
No Required validation in xhtml + JSF
Internal servlet error?
why i can not use f:param inside an html form? what is the solution for it?
Value is session managed bean's attribute is nulled
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:58:02.