Questions tagged [controller]

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). This is often used in conjunction with the Spring or model-view-controller tags.

A controller is responsible for executing a sequence of instructions in response to some stimulus (maybe a command, action, or event). It may be used to refer to the controller portion of the MVC (Model-View-Controller) pattern, or a general handler for actions and events that orchestrates a response. It may also refer to the Spring annotation @Controller.

As it can refer to a number of different things, this tag is best used in conjunction with other tags. So, if you're referring to the Spring @Controller annotation, use the Spring tag in conjunction with this one. If you're referring to the general MVC controller, use the model-view-controller tag.

16598 questions
77
votes
7 answers

In Spring MVC, how can I set the mime type header when using @ResponseBody

I have a Spring MVC Controller that returns a JSON String and I would like to set the mimetype to application/json. How can I do that? @RequestMapping(method=RequestMethod.GET, value="foo/bar") @ResponseBody public String fooBar(){ return…
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
76
votes
2 answers

Fat models, skinny controllers and the MVC design pattern

I just read a blog post that explains MVC with a banking analogy. I have a few months of experience with web application development with an MVC framework (CakePHP), so I get the basics, but I began to see a theme that made me think I'm taking a…
ryonlife
  • 6,563
  • 14
  • 51
  • 64
76
votes
8 answers

Can Spring Security use @PreAuthorize on Spring controllers methods?

Can Spring Security use @PreAuthorize on Spring controllers methods?
egervari
  • 22,372
  • 32
  • 121
  • 175
70
votes
15 answers

Mockito Exception - when() requires an argument which has to be a method call on a mock

I have a very simple test case that is using Mockito and Spring Test framework. When I do when(pcUserService.read("1")).thenReturn(pcUser); I get this exception. org.mockito.exceptions.misusing.MissingMethodInvocationException: when() requires…
jsf
  • 2,851
  • 9
  • 30
  • 33
70
votes
6 answers

Angularjs - Pass argument to directive

Im wondering if there is a way to pass an argument to a directive? What I want to do is append a directive from the controller like this: $scope.title = "title"; $scope.title2 =…
SKYnine
  • 2,708
  • 7
  • 31
  • 41
70
votes
13 answers

Why is it that "No HTTP resource was found that matches the request URI" here?

I have code in my controller like so: [Route("api/deliveryitems/InsertIntoPPTData/{stringifiedRecord}")] ...and I'm calling it via Postman like so: …
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
69
votes
9 answers

how to create global function that can be accessed from any controller and blade file

I have two controller file homecontroller and backendcontroller. What is the best way to create global function and access it from both files? I found here Arian Acosta's answer helpful but I wonder if there is an easiest way. I would appreciate…
Johnny
  • 1,685
  • 6
  • 24
  • 42
68
votes
6 answers

How to call a function from another controller in AngularJS?

I need to call a function in another controller in AngularJS. How can I do this? Code: app.controller('One', ['$scope', function($scope) { $scope.parentmethod = function() { // task } } ]); app.controller('two',…
Bhavesh Chauhan
  • 1,023
  • 1
  • 11
  • 30
62
votes
2 answers

ASP.NET MVC: returning plaintext file to download from controller method

Consider the need to return a plain-text file from a controller method back to the caller. The idea is to have the file downloaded, rather than viewed as plaintext in the browser. I have the following method, and it works as expected. The file is…
p.campbell
  • 98,673
  • 67
  • 256
  • 322
62
votes
6 answers

In Rails when a resource create action fails and calls render :new, why must the URL change to the resource's index url?

I have a resource called Books. It's listed as a resource properly in my routes file. I have a new action, which gives the new view the standard: @book = Book.new On the model, there are some attributes which are validated by presence, so if a…
rcd
  • 1,348
  • 1
  • 14
  • 27
60
votes
7 answers

post and get with same method signature

In my controller I have two actions called "Friends". The one that executes depends on whether or not it's a "get" versus a "post". So my code snippets look something like this: // Get: [AcceptVerbs(HttpVerbs.Get)] public ActionResult Friends() { …
codette
  • 12,343
  • 9
  • 37
  • 38
59
votes
21 answers

How to return an HTML page from a RESTful controller in Spring Boot?

I want to return a simple HTML page from a controller, but I get only the name of the file not its content. Why? This is my controller code: @RestController public class HomeController { @RequestMapping("/") public String welcome() { …
Gustavo
  • 3,461
  • 7
  • 26
  • 41
59
votes
7 answers

How to get list of all routes of a controller in Symfony2?

I have a controller which implements all routes/URL(s). I had the idea to offer a generic index over all help-pages. Is there a way to get all routes defined by a controller (from within a controller) in Symfony2?
Sammy
  • 1,178
  • 1
  • 14
  • 27
55
votes
2 answers

How to tell which format a controller has resolved to render

In a rails controller action with the following code: respond_to do |format| format.json{ render :json=> {:status => 200, :response=>@some_resource} } format.html { redirect_to(some_resource_path)} end How can I log the format the controller…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
51
votes
6 answers

A component is changing an uncontrolled Autocomplete to be controlled

Can you tell me that why I'm getting error "A component is changing an uncontrolled Autocomplete to be controlled. Elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled…