concept action method in category java

appears as: n action method, action method, ction methods, ction method, An action method, action methods, The action method, The action methods
Play for Java

This is an excerpt from Manning's book Play for Java.

This defines an action method that generates an HTTP “OK” response with text content. If you still have the application running, you can save the file and reload http://localhost:9000/; it will serve a plain text document containing the customary greeting, as seen in figure 1.4.

Listing 3.1. Adding action methods

In Play, a controller is an aggregation of action methods. An action method is a static method that takes some parameters as input and always returns an instance of (a subclass of) the Result class. In other words, an action method always takes the following form:

public static play.mvc.Result methodName(params...)

Note that action methods are static. This is because controllers are effectively singletons, which fits the HTTP approach. Because HTTP doesn’t have the concept of an object but is mainly procedural, we shouldn’t try to map those object concepts in our controller. You should really think of your action methods as the entry point from HTTP to your application. You could compare them to the static main() method of a Java program.

Since an action method mainly serves as an entry point, you shouldn’t put too much business logic into your controllers and action methods. Rather, you should do what is necessary to translate an incoming HTTP request to data your business logic understands, hand it off to that business logic, and translate the result into an HTTP response.

An action method is a Java method that processes the request parameters and produces a result to be sent to the client. The action method is where the response is processed. Each action method returns a result, represented by a play.mvc.Result value, which represents an HTTP response.

Portlets in Action

This is an excerpt from Manning's book Portlets in Action.

The UserRegistrationPortlet class extends the GenericPortlet class and makes use of @RenderMode and @ProcessAction annotations to specify the portlet’s render and action methods. The following code snippet shows the init method:

Figure 6.3. This Book Catalog portlet implementation makes use of the <actionURL> tag’s copyCurrentRenderParameters attribute to send the book’s ISBN to the action method responsible for uploading the book’s TOC. The book’s ISBN is used to name the uploaded TOC file.
if(synchronizeOnSession) {
   synchronized(mutex) {
    //invoke render or action method
  }
}

The @Controller type-level annotation accepts an optional value element, which specifies the logical name of the controller component. The value element is the same as the id attribute of a bean element, which you used in chapter 7 to define objects in the web application context XML file. As you can see, AddBookController doesn’t extend or implement a Spring-specific class or interface. The showAddBookForm method is a render method of the controller. The addBook method represents an action method of the controller.

In listing 8.10, the @ActionMapping annotation marks the addBook method as an action method of AddBookController. The optional params element specifies request parameter name-value pairs, which must be present in the portlet request to invoke the addBook method. The addBook method is invoked if the portlet mode is VIEW and the value of the myaction request parameter is addBook.