3.3.2 Layout
Layout is equivalent to the container of Screen, Navigation. Responsible for the layout control of the page.
Template Layout, actually uses Velocity to make page layout control with Velocity as a .vm file as a Layout template.
We have seen a template for a Layout in Section 2.2. It can be seen that in this template file, there is no data containing any display, only some HTML elements used to control the layout. Okay, I believe that you understand what I will say: The Layout Template is equivalent to a box with a lot of plaid. The only thing we need is to put these "plugins" such as Navigation, Screen to these plaids. At this point, Layout is equivalent to the Controller in the presentation layer. Writing here, I can't help but express my heart and gratitude for Turbine developers.
In the previous section, we have made a simple Screen with Velocity. In addition to the need to change the base category to VelocityOnlyLayout [i], the steps written in Layout using Velocity are exactly the same. The Layout Template file is placed in the "templates-path / layouts /" directory.
Now let's take another few main variables in the Layout template in Section 2.2:
l $ screen_PlaceHolder - a very important variable. The place where this variable is placed is where SCREEN will be output. This variable is filled in the SCREEN text information saved in the String object.
l $ navigation - This variable is used to get navigation. Its object type is: org.apache.turbine.util.Template.templatenavigation.
l $ data - don't say more, it is Rundataj.
3.3.3 Navigation
Navigation's Velocity implementation is completely consistent with Screen, Layout. The Navigation Template is placed in the "Templates-path / navigations /" directory. The base class that can be used is: velocitynaVigation.
3.3.4 Action
When the URI entered in the browser contains an action parameter, it is like this:
http://www.server.com/servlet/turbine/template/helloworld.vm/Action/UpdateWorld
Action will be triggered and executed.
At this point, Turbine is performed in the following order:
First, the UpdateWorld Class, located under "Web-INF / CLASS / COM / YOURPAMPANY / App / Modules / Actions /" will be executed; then, execute the HelloWorld Class (if present); finally, execute helloworld.vm.
Action is a module that performs a specific transaction. These transactions may be sent to a Mail, or it is also possible to operate databases, or other possible transactions. No value is returned after the Action execution ends, and it is only possible to place a Message in Rundata via the Rundata.setMessage () method. However, during the Action's transaction process, it is possible to change or interrupt the Template and Screen of Up to be executed.
Velocity also provides support for Action, but is different from the three modules mentioned above (Screen, Layout, Navigation), and Action does not need to write the corresponding template file. The following table is a simple action: package com.yourcompany.app.modules.Actions;
// velocity stuff
Import org.apache.velocity.Context.context;
// Turbine Stuff
Import org.apache.turbine.util.Rundata;
Import org.apache.turbine.modules.Actions.VelocityAction;
Public Class AddUser Extends VelocityAction
{
Public void doperform (Rundata Data, Context Context) Throws Exception
{
IF (Data.GetParameters (). getString ("UserName", NULL) == NULL)
{
Data.setMessage ("UserName Does Not Exist";
SetTemplate (data, "adduser.vm);
Return;
}
// Store User Info INTO DATABASE
Data.setMessage ("Information Stored!");
SetTemplate (Data, "MainMenu.vm");
// stuff unnthing Into the velocity context
Context.put ("Variable", "foo");
}
}
It checks if the submitted data contains "username" variables. If not included, it will switch to the "adduser.vm" template and display an error message. Otherwise, switch to "MainMenu.vm" and display the corresponding prompt information, in addition to this, some data is placed in Velocity Context.
3.3.4.1 Velocity Action Event
The above is just a simple usage of Action, and Turbine also provides a mechanism that is an action event. With the Action Event mechanism, Turbine provides a very convenient way to process the Form Submission, making us more quickly develop Turbine applications.
In order to understand the principles of the Action Event mechanism, let's review Turbine's related content J:
When Turbine accepts a URI containing the Action request, first execute this action, then ... oh, right, that is. However, for those classes inherited from ActionEvent, some wonderful things have occurred when this Action is executed ...
Leave a suspense first, let us look at the code J:
Public Class NewUserfoo Extends VelocityAction
{
Public Void Doadd (Rundata Data, Context Context) Throws Exception
{
// put code here to add the user to the system
Context.put ("UserName", UserName;
Data.setMessage ("User Added!");
Public void doperform (Rundata Data, Context Context) Throws Exception
{
Data.setMessage ("Button Not Found!");
}
}
Then, in our HTML TAG embedded in this code:
...