Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

In the Using Tags lesson, we implemented a login Logon form. In this lesson, we interpret the Logon form, and return a different result code depending on the circumstances.

If you have coded along on localhost, you can open the Logon action.

Code Block
http://localhost:8080/tutorial/Logon.action

Enter and enter a likely username and passowrd, and press Enter. Since we haven't given the Action any behavior, it redisplaysthe redisplays the default Logon.jsp page.

Let's add an Action class that will make the Logon page form more interesting.

The Code

Just as an example, lets look at we can examine the username and password values. If either or both properties are empty, return INPUT, so that we can collect a valid logonLogon. Otherwise, return SUCCESS.

Code Block
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class Logon extends ActionSupport {

    public String execute() throws Exception {

        if (isInvalid(getUsername())) return INPUT;

        if (isInvalid(getPassword())) return INPUT;

        return SUCCESS;
    }

    private boolean isInvalid(String value) {
        return (value == null || value.length() == 0);
    }

    private String username;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    private String password;
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}

How The Code Works

The framework automaticaly populates the username and password properties for us. All that's left to do is checking to see if either property is emptyWhile the action decides which result to next invoke, it does not decide what the result actually does. For that, we need to turn to selecting results.

Next

Onward to Selecting Results

Prev

Return to Hello World