Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Stucts2 values on the page and how the attribute values corresponding to the Action     - Linux System Getting Started Tutorial: Linux file permissions brief description (Linux)

- CentOS 6.7 compile and install LAMP (Server)

- Under Ubuntu on how to use iptables firewall (Linux)

- How to install and use the malware detection tool LMD and ClamAV antivirus engine on Linux (Linux)

- Quick Install software RAID on Linux (Linux)

- Keepalived + HAProxy high availability load balancing (Server)

- Installation image conversion tool on your Ubuntu Converseen 0.8.1 (Linux)

- [Errno 4] IOError: [Errno ftp error] with yum appears as a workaround (Linux)

- Linux partition command (Linux)

- Android screen rotation processing and ProgressDialog the best AsyncTask (Programming)

- Qt for file splitting and fusion gadgets (Programming)

- Ceph Source Analysis: Network Module (Server)

- MySQL and MariaDB traditional master-slave cluster configuration (Database)

- 11.2.04 Oracle RAC directory crfclust.bdb file is too large, Bug 20186278 (Database)

- PostgreSQL-- run Supervisord on Docker in Ubuntu (Database)

- Close and limit unused ports computer server security protection (Linux)

- Ceph distributed storage system is installed on a CentOS 7.1 (Server)

- Linux system on how to use rsync to synchronize data (Server)

- How to configure AWStats in Ubuntu Server (Server)

- Installation and use of Linux Sniffer tool Tcpdump (Linux)

 
         
  Stucts2 values on the page and how the attribute values corresponding to the Action
     
  Add Date : 2016-08-05      
         
         
         
  In Strut2, the data and the Action page, there are two basic ways correspondence: are: attribute-driven (FieldDriven) and model-driven (ModelDriven). Attribute-driven divided into two cases: one is the property corresponds to the basic data types: the other is the corresponding JavaBean style property. Here are a look at what they mean are how to achieve.

Attribute-driven (FieldDriven): Property corresponding to the basic data types

In index.jsp, I wrote

< Form action = "helloWorldAction.action" method = "post">
    Account: < input type = "text" name = "account" />

    Password: < input type = "password" name = "password" />
    < Input type = "submit" value = "Submit" />
  < / Form>

In Action is written like

public class HelloWorldAction extends ActionSupport {
 
    private String account;
    private String password;
    
    public String getAccount () {
        return account;
    }
    public void setAccount (String account) {
        this.account = account;
    }
    public String getPassword () {
        return password;
    }
    public void setPassword (String password) {
        this.password = password;
    }
    
    // Other code omitted ....
}
It can be found on the page index.jsp the name of the property, and Action properties are the same name. As a result, when the page is submitted, Struts2 will automatically request from the object in the data extracted, and then follow the corresponding name is automatically set to go Action property inside.

2. attribute-driven FieldDriven (JavaBean style property of correspondence)

 (1) take a look at the wording of the domain object, according to the JavaBean style to write the sample code as follows:

public class HelloWorldModel {
    
    private String account;
    private String password;
    public String getAccount () {
        return account;
    }
    public void setAccount (String account) {
        this.account = account;
    }
    public String getPassword () {
        return password;
    }
    public void setPassword (String password) {
        this.password = password;
    }
}
(2) At this time there are changes in the wording of Action, mainly the direct use of this object, in fact, is the definition of a property like this is the type of object, and then provide the appropriate getter () and setter () method for this property can be. If you set this property to access the properties for the public do not need to getter () and setter () method. Action modified sample code is as follows:

 public class HelloWorldAction extends ActionSupport {
 
    private HelloWorldModel hwm = new HelloWorldModel ();
 
    public HelloWorldModel getHwm () {
        return hwm;
    }
 
    public void setHwm (HelloWorldModel hwm) {
        this.hwm = hwm;
    }
    // Other code omitted ....
}

 (3) After the Action changes, index.jsp page content must also be changed accordingly, otherwise the data will not correspond correctly, mainly in the corresponding attribute name, add a prefix to a domain object, indicating the value is in the end corresponding to the inside where Yu-brother to the domain object, for example:

< Form action = "helloWorldAction.action" method = "post">
        Account: < input type = "text" name = "hwm.account" />

        Password: < input type = "password" name = "hwm.password" />
        < Input type = "submit" value = "Submit" />
    < / Form>
< / Body>

3. Model-Driven (ModelDriven)

  It's basically a way to make Action ModelDriven implement the interface that we need to implement getModel approach. The return value is the data model object Action used this method. The modified sample code is as follows:

 public class HelloWorldAction extends ActionSupport implements ModelDriven {
 
    private HelloWorldModel hwm = new HelloWorldModel ();
 
    public Object getModel () {
        // TODO Auto-generated method stub
        return hwm;
    }
    // Other code omitted ....
}

In index.jsp also need to make the appropriate adjustments, mainly just to name attribute is to remove the added hwm prefix. Its sample code is as follows:

 < Form action = "helloWorldAction.action" method = "post">
        Account: < input type = "text" name = "account" />

        Password: < input type = "password" name = "password" />
        < Input type = "submit" value = "Submit" />
 < / Form>

Why kind of approach does not require a prefix of it?

  Because the use of such ModelDriven way, a Actiion only correspond to a Model, there is no need to add a prefix, Struts2j know, the value of the account corresponds to the Model page of account properties.
     
         
         
         
  More:      
 
- The Java way to stop a thread of execution (Programming)
- How to test your MongoDB application upgrade? (Database)
- Modify Linux terminal prompt path length (Linux)
- Linux software firewall ACL match point optimization (Linux)
- The Java Properties class action (Programming)
- Ubuntu 14.04 LTS to compile the source code Android4.4.2 (Linux)
- SSH port forwarding application (Server)
- Easily create RPM packages using the FPM (Linux)
- linux firewall configuration (Linux)
- Apache site default home page settings (Server)
- Linux 6 install Oracle 11g (64bit) (Database)
- 14.04.3 Ubuntu configuration and successfully compiled source code Android 6.0 r1 (Programming)
- C ++ CBitmap, HBitmap, Bitmap difference and contact (Programming)
- Learning OpenCV: (VS2010-openCV2.4.3-win7 configuration instructions) (Linux)
- Puppet installation and testing (Server)
- Ubuntu 14.10 Server configuration wireless Internet access (Server)
- Deep understanding of C # generics (Programming)
- Java source implementation of the observer pattern instance (Programming)
- NAT (network address translation) Realization (Linux)
- NFS-based services and service utilization Corosync DRBD high availability cluster configuration, respectively (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.