The Struts2.0 Model:- System State &
Business Logic JavaBeans
Introduction:-The
model is the internal state of the application. This state is composed of both
the data model and the business logic. From the high-level black box view, the
data and the business logic merge together into the monolithic state of
the application. For instance, if you are logging in to an application, both
business logic and data from the database will be involved in the authentication
process. Most likely, the business logic will provide an authentication method
that will take the username and password and verify them against some persisted
data from the database.
Class/Library
File Descriptions:-
Actions do three things.
Actions Encapsulate The Unit of Work:-
The action fulfills the role of the MVC model for the framework.
responsibilities of this role is business logic; actions use the execute()
method for this purpose. The code inside this method
should concern itself only with the logic of the work associated with the
request.
Actions
Provide Locus For Data Transfer:- Being
the model component of the framework also means that the action is expected to
carry the data around .Since the data is held local to the action, it’s always
conveniently available during the execution of the business logic. There might
be a bunch of JavaBeans properties adding lines of code to the action, but when
the execute() method references the data in those properties, the proximity of
the data makes that code all the more succinct.
Actions
Return Control String For Result Routing:- The
final duty of an action component is to return a control string that selects the
result that should be rendered.
Source Code Example:-
Actions Encapsulate The Unit of Work:-
public String execute() {
setCustomGreeting( GREETING + getName() );
return "SUCCESS";
}
Actions Provide Locus For Data Transfer:-
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String customGreeting;
public String getCustomGreeting()
{
return customGreeting;
}
public void setCustomGreeting( String customGreeting ){
this.customGreeting = customGreeting;
}
Actions Return Control String For Result Routong:-
<action name="HelloWorld" class="manning.chapterOne.HelloWorld">
<result name="SUCCESS">/chapterTwo/HelloWorld.jsp</result>
<result name="ERROR">/chapterTwo/Error.jsp</result>
</action>