saoj
Joined: 22/12/2007 07:20:02
Messages: 22
Offline
|
In Mentawai an action is a piece of code that gets executed when the Mentawai controller receives a HTTP request from the browser. As we have seen before, this can be a class that extends BaseAction, a class that implements Action or any regular POJO (Plain Old Java Object).
By default, if you make a request to http://www.mysite.com/HelloAction.hello.mtw, the controller understands that you want to call the hello() method of the HelloAction class. You can also omit the method part, like in http://www.mysite.com/HelloAction.mtw and the controller assumes that you want to call the method execute() from the HelloAction class.
Mentawai uses the term inner action for the hello() method. An action class such as HelloAction.java can have many inner actions inside it. These inner actions are nothing more than the instance methods of the action class.
For example, we may have an action class like this:
We say that the LoginAction has no inner actions. The LoginAction class is the action itself, in other words, you can call it with the following URL:
http://www.mysite.com/LoginAction.mtw
You can also call it like this, although it would not make much sense:
http://www.mysite.com/LoginAction.execute.mtw
Now we can add a new method to the LoginAction, in other words, we are adding an inner action to the LoginAction class.
An now to call the inner action sayHello you would use the following URL:
http://www.mentaframework.org/HelloAction.sayHello.mtw
It is important to understand the inner action concept because some methods take a String as the innerAction parameter. For example, we can make our action implement the Validatable interface, to setup some validation code:
Note that for the execute method, we consider that there is no inner action, so the innerAction is null and not "execute". The execute() method is kind of the natural method of an action class, in other words, it is the method that gets executed when no inner action is specified in the request URL.
The only way to get the innerAction parameter to be equal to "execute" is to call the action with the following URL: http://www.mysite.com/HelloAction.execute.mtw, which does not make much sense. If you want to call the "execute" method, you should make a request like: http://www.mysite.com/HelloAction.mtw, and the innerAction will be null.
|