2. model-driven (model-driven) action. Action exposes a model class through the get method. form fields correspond to the attributes of the model class. The model-driven concept is not directly related to the com. opensymphony. xwork. modeldriven interface. Our action does not implement the com. opensymphony. xwork. modeldriven interface or model-driven. For example:
Java code
- User. Java
- Public ClassUser {
- PrivateString username;
- PrivateString password;
- PrivateString email;
- ......
- Get ();/set (); Method
- ..........
- }
- Registeraction. Java
- Public ClassRegisteractionImplementsAction {
- PrivateUser user =NewUser ();;
- PublicString execute ();ThrowsException {
- // Perform User Registration
- }
- PublicUser getuser ();{
- ReturnUser;
- }
- }
- Page register.html contains:
- ......
- <Input name = "user. username">
- .......
User. java public class user {private string username; private string password; private string email ;...... get ();/set (); Method ..........} registeraction. java public class registeraction implements action {private user = new user (); Public String execute (); throws exception {// execute user registration operation} public user getuser (); {return user ;}} page register.html contains :...... <input name = "user. username "> .......
Model-driven accesses data through the ognl Expression Language. For example, during registration, the expression language user. username will execute getuser. setusername (). So what is the com. opensymphony. xwork. modeldriven interface? It puts the model obtained by the object GetModel () in valuestack. It can be understood that the attribute of this model is appended to the action. It is mainly used to implement the formbean function similar to struts. Conclusion: If model-driven (model-driven) action is considered to be com. opensymphony. xwork. the modeldriven interface is incorrect. model-driven and COM. opensymphony. xwork. the modeldriven interface has no direct relationship. In practical applications, we generally use model-driven and field-driven together, and do not need to completely distinguish these two concepts.
1. field-driven (field-driven) action. Action has its own attributes. These attributes are generally the basic types of Java. The form field corresponds directly to the action attribute.