spring-mvc

Null check in different layers (presentation layer, middle, database)

Hi, Our application is developed using Spring framework. Is it good practice to check null condition in all layers (presentation. business, database) ? The flow in our application is Form submission -> jQuery validator -> Spring validator -> Controller -> Service -> Database Currently we are checking the parameters for null condition ...

Spring MVC; avoiding file extension in url?

I just started with Spring Web MVC. I'm trying to avoid file extenstions in the url. How can i do this? (I'm using Spring 2.5.x) Bean: <bean name="/hello.htm" class="springapp.web.HelloController"/> I want it to be: <bean name="/hello" class="springapp.web.HelloController"/> I cannot get it to work. Any ideas? Edit: Url-mapping ...

How to unit test a Spring MVC controller using @PathVariable?

I have a simple annotated controller similar to this one: @Controller public class MyController { @RequestMapping("/{id}.html") public String doSomething(@PathVariable String id, Model model) { // do something return "view"; } } and I want to test it with an unit test like this: public class MyControllerTest { @Test ...

In what case would a programmer get the webApplicationContext out of DispatchServlet?

I notice that there is getWebApplicationContext in org.springframework.web.servlet.mvc.AbstractController. This means that spring programmers can use getWebApplicationContext to access beans in the spring IoC container. However, I never see people use this way to get beans in all the spring MVC tutorials. So here comes my question, in ...

Displaying a result of a query from the database in increments

I want to display a list of all the users in my site but I only want to display 10 people per age. I don't know how exactly to do this. I know how to do it by just displaying all the users in one page but that's not very good is it? If I do it with the code I have now, it will only get the first ten users over and over again. I want t...

asp.net mvc vs spring mvc

Hi, Can anyone please make a comparison of "asp.net mvc" vs "spring mvc (java)". Which technology is better in performance, productivity, maintenance, features,... Regards, sirmak ...

What Spring MVC controller to use for form with dynamic fields .

I have a form where I have two fields that I can add as much as I can. Think of it as like the upload file in gmail where I can add 1,2,3... files to upload only that I have two fields. I am not so sure how this will check out using a SimpleFormController in Spring. Will the Spring Controller bind the them automatically? My command cl...

Command Objects in Spring

I have a command object composed of primitive fields and an object field. How do I bind my form fields to the fields in the object? I tried doing this but to no avail <form:form commandName="course" method="POST"> <form:input path="activity.activity"/> . . . </form:form> I get this error org.springfr...

Dynamic Forms in Spring

I am trying to make a dynamic form using Spring forms. Basically, the form gets a title of learning activity and then there's the a button below it that says, "Add one more Learning Activity". This makes it possible for the user to add one more learning activity. I want him to be able to add as much as he likes. I haven't tried this be...

Component controller in Spring-MVC

I am designing a web application that requires loading multiple components on a single page. (In terms of page layout is similar to Google reader) I like to keep these components separate from each other (for reasons such as reusability). For example, I have a left panel that let's user navigate among multiple feeds that he's subscribed...

Override velocity view and output an image instead

I have hijacked the normal processing of velocity templates by calling response.getOutputStream in my controller, and I do get an image, but there is an exception "java.lang.IllegalStateException: getOutputStream() has already been called for this response" whenever an image is generated. Is there a way to tell velocity not to parse the ...

@Secured throws AccessDeniedException although roles are correct

After solving all authentication related problems in my first Spring web application I'm now stuck with authorization. Configuration using @Secured annotations is pretty straight-forward so I don't think I made a mistake here. Additionally I'm using an Active Directory using the LDAP authentication provider and assign roles by AD groups...

Spring sessionForm in Google AppEngine

My sessions in Google Appengine works in the development environment but not when I deploy it. I have sessions-enabled set to true in my appengine-web.xml. Am I missing something here? I had to override the initBinder in my Controller for it to work in appengine because Spring tries to "access the system class loader" Maybe I should a...

How to set up a global prefix and suffix used in each error field in Spring ?

Hi, In Struts, you can confire a global prefix and suffix in a resource bundle file. Something like: errors.prefix=<div class="error"> errors.suffix=</div> So <div class="error"> will be added before each <html:errors and </div> will be added after each one. So how can i get the same effect by using Spring form tags <form:errors ? ...

How can i get error message in form:errors tag by using MultiActionController ?

Hi, I have a form <form:form commandName="command" method="post"> <form:errors path="property"/> // some fields </form:form> And a MultiActionController Command command = new Command(); ServletRequestDataBinder binder = createBinder(request, command); binder.bind(request); for (Validator validator: getValidators()) if...

Spring-MVC is adding on an extra .jsp extention to the URL a user enters

The error message I get is description The requested resource (/gradebook/WEB-INF/jsp/hello.jsp.jsp) is not available. I have a WEB-INF/jsp directory that contains hello.jsp Spring appears to be adding the jsp extension and I can't figure out why. I've pasted my web.xml and my gradebook-servlet.xml below. <?xml version="1.0" encoding="U...

How do you unit-test controllers that oauth?

I like Spring MVC because you can unit test your controllers. But testing controllers that oauth is another thing. For instance if I want to get the authorization url because I want to Oauth to GData, I would have to deploy the web-app because Google will only accept authorization requests from my domain (the url of my web app), not my...

Spring Dispatcher Servlet not working

I am trying to create a a simple Spring dispatcher Servlet as a base for my application. I want to initialize logging and security in the controller and then redirect the user to my application. I have tried several examples from the net, but it is not working. Please share with me a complete code so that I could try it. I do not want a...

Framework Recommendation request: spring, struts, j2ee?

The last time I looked at web applications, the consensus seemed to be Struts/J2EE. Now, it looks like Spring MVC/J2EE or Struts/J2EE are both viable solutions. Is this generally correct? Or is Spring MVC now the consensus choice over Struts? We have at least one guy who has worked with Struts before and wants to go with that. I'm more f...

Controller's life-cycle in Spring MVC

What is the lifecycle of a Controller in Spring MVC? When is the controller created, when destroyed? Is it shared among multiple threads? Can it be in use simultaneously by more than one request. ...