Model Driven
来源:互联网 发布:ps4网络nat类型失败 编辑:程序博客网 时间:2024/05/23 01:35
Struts 2 does not have "forms" like Struts 1 did. In Struts 2 request parameters are bound directly to fields in the actions class, and this class is placed on top of the stack when the action is executed.
If an action class implements the interface com.opensymphony.xwork2.ModelDriven
then it needs to return an object from the getModel()
method. Struts will then populate the fields of this object with the request parameters, and this object will be placed on top of the stack once the action is executed. Validation will also be performed on this model object, instead of the action.
Interceptor
To use ModelDriven
actions, make sure that the Model Driven Interceptor is applied to your action. This interceptor is part of the default interceptor stack defaultStack
so it is applied to all actions by default.
Example
Action class:
public
class
ModelDrivenAction
implements
ModelDriven {
public
String execute()
throws
Exception {
return
SUCCESS;
}
public
Object getModel() {
return
new
Gangster();
}
}
Gangster class (model):
public
class
Gangster
implements
Serializable {
private
String name;
private
int
age;
private
String description;
private
boolean
bustedBefore;
public
int
getAge() {
return
age;
}
public
void
setAge(
int
age) {
this
.age = age;
}
public
boolean
isBustedBefore() {
return
bustedBefore;
}
public
void
setBustedBefore(
boolean
bustedBefore) {
this
.bustedBefore = bustedBefore;
}
public
String getDescription() {
return
description;
}
public
void
setDescription(String description) {
this
.description = description;
}
public
String getName() {
return
name;
}
public
void
setName(String name) {
this
.name = name;
}
}
JSP for creating a Gangster:
<
s:form
action="modelDrivenResult" method="POST" namespace="/modelDriven">
<
s:textfield
label="Gangster Name" name="name" />
<
s:textfield
label="Gangster Age" name="age" />
<
s:checkbox
label="Gangster Busted Before" name="bustedBefore" />
<
s:textarea
cols="30" rows="5" label="Gangster Description" name="description" />
<
s:submit
/>
</
s:form
>
Generated by CXF SiteExporter
摘自 http://struts.apache.org/release/2.3.x/docs/model-driven.html
- Model-Driven
- Model Driven
- Property-Driven和Model-Driven
- Model-Driven Software Development
- Model Driven Engineering
- Model Driven Architecture
- Model Driven Architecture
- Struts2 Model-Driven
- Agile Model Driven Development (AMDD)
- event driven gui programming model
- webwork的property-driven 和model-driven的理解。
- Model-Driven Design Using Business Patterns
- Model-Driven Software Development: Integrating Quality Assurance
- Model Driven Architecture 模型驱动架构
- Introduction to Model Driven Development with AndroMDA
- MDD Model-Driven Developement 模型驱动开发
- MDA Model Driven Architecture 模式驱动开发
- Struts Model-Driver and Field-Driven
- 大数据存取的选择:行存储还是列存储?
- java中如何创建自定义异常Create Custom Exception
- HTML字符实体和转义字符串大全
- fmt标签的格式化日期使用
- A Journey to America’s Past -- 美国怀旧之旅(一)
- Model Driven
- wikioi 1056圆内三角形统计
- sql 脚本查看死锁并解锁
- 含有图片上传功能的请求及数据库的存储
- Android Launcher分析和修改12——Widget列表信息收集
- Dijkstra算法(单源最短路径)
- 在同一个地方生活
- Java基础视频教程-概述
- NSArray 演示(无注释)