JSF with Spring Controllors - java

I am new to Spring and JSF,and I want to integrate JSF for the front end, and use Spring controller. Can Anyone give me a explanation or an example how this can be done?. Basically what I want is a form submission (which will create a Business object and feed it to the database) and navigate using controllers.
The required xml files ? and its element?
A Basic form( ex: Like a User registration )
Spring class with #Controller, and #RequestMapping etc.
I just want to know how the form submission works and the flow of that.

If you want to integrate Spring with JSF you don't need to use #Controller and #RequestMapping, those are for SpringMVC. JSF itself has navigation mechanism use that.
If you need example check Integrate Spring into JSF 2

Related

Spring MVC bean data flow

I got task unfortunately from work to create page using spring mvc, but i never work with that. I have to do that web app with restricted specifications which are following:
JSP cannot contain javascript, java, jstl only spring mvc tag's, but it's not everything. Controller must containt vaiable's only inside methods, all methods can return only String or void, so I'm unable to use #ModelAttribute, ModelMap, Model to move data from one view to another.
Is it possible to create page with following rules? I dont realy know how beans work in Spring MVC, but it seems that it will doesnt work without it.

Role based menu in Java EE

I am using Spring MVC for my web application. My views are JSP based. What is the best practice to show role based menus?
Should I make a check on the JSP page for a role?
Should I build the menu in a Java class and pass it to a JSP page to show up?
Anything else?
Use a framework like Spring Security instead of implementing the complete security infrastructure on your own. Like all other Spring modules, you would simply configure the framework declaratively using XML (for defining roles etc.) and so it's quite flexible.
Spring Security comes with its own tag library that you would then use to secure your HTML elements. For example, to make a menu item available for Admin roles only just wrap it in an appropriate <sec:authorize> tag.
References:
Spring Source is a good place to begin with. Have a look at this video as well from their YouTube channel. Getting Started with Spring Security 3.1
Make different role based menu pages and include them in you main content page at runtime.

harmony between webflow and Spring MVC Controllers

Spring 2.5.6SEC02
Spring Webflow 2.0.9
I have a normal flow in which I have a form in flow scope. I now want to call my annotated spring MVC #Controller and get access to the form information. I basically want to display details as a modal dialog box on the screen. I've been reading up on spring-js, but I'm not very familiar with it and it seems to want to incorporate dojo into my code.
Thanks in Advance.
You can keep the form in session scope instead, that way it is available both to webflow and other controllers. That will however mean that it is shared between tabs and possibly reused in later conversations (Though you can probably prevent that).
Another solution is passing the flow execution key to the controller and have the controller read it from the FlowExecutionRepository.

Architecture of a Spring MVC application with AJAX / JSON / REST

First, I developed a Java EE application with a Adobe Flex frontend and I used BlazeDS.
So I had in the Java backend this structure:
IServiceX -> ServiceImplX -> IDaoX -> DaoImplX
So the frontend called a service like "addUser(User u)". The service implementation calls the Dao interface which implements a Dao to a database and the User is added. The return value is the new User ID.
Now I want to use instead of Adobe Flex HTML5 with AJAX. So I found this example project:
https://src.springframework.org/svn/spring-samples/mvc-ajax/
I have the problem how to integrate this into my existing architecture.
In this case I have a domain object called Account.java and a controller AccountController.java:
https://src.springframework.org/svn/spring-samples/mvc-ajax/trunk/src/main/java/org/springframework/samples/mvc/ajax/account/AccountController.java
Is it okay to create a Controller and this controller calls the already existing services?
Or should I update/change my architecture (but I do not know how...)?
Thank you in advance & Best Regards.
You are right - simply create a XController, annotated with #Controller and inject your existing service there. Take a look at Spring MVC docs. Also check the ajax simplifications article for spring mvc 3.0

url-action mapping & routing in Spring MVC 3.0

I'm developing a web application using Spring MVC 3.0 and looking for a ready-made solution, if any, or a "best practices" reference for a url/action mapping and routing system that can achieve the following:
REST-friendly controller / method name to view mapping. The current mapping implementation translates the request to a view name, which may be problematic when using several parameters and is incompatible with REST urls
A service that accepts the name of a controller, a method and arguments values and renders the URL that's represented by them
Integration with Spring Security that can allow me to check for a given URL whether the current user is allowed to access it, so that I can decide whether or not to render a URL
A menuing system based on the above that can define menues composed of these actions and render them to page
Basically what I need is the ability to define URLs in one centralized place, so that changing a URL (during development; I'm aware of the don't-change-live-urls idea :) ) does not mean looking up and changing that URL in a zillion pages.
Any directions to such an existing solution / tutorial / guide would be great.
Thanjs
This is a feature I really miss in Spring MVC.
That's why I created the springmcv-router project, basically a port of PlayFramework's Router implementation in Spring MVC (HandlerMapping + HandlerAdapter).
I'm heavily using it in several real-world projects and the Router implementation itself is reliable.
Try using Spring Roo. It utilizes many best practices for spring MVC, and it has a scaffolding feature that automatically maintains a menu, jsp's and all the CRUD methods of a controller.
Setting up Spring Security with Roo is as simple as typing "security setup".
Hope this is helpful.

Categories