Code:
<flow>
<start-state idref="enterLoginDetails" />
<view-state id="enterLoginDetails" view="enterLoginDetails">
<render-actions>
<action bean="loginFormAction" method="setupForm" />
</render-actions>
<transition on="login" to="performLogin">
<action bean="loginFormAction" method="bindAndValidate" />
</transition>
</view-state>
<action-state id="performLogin">
<action bean="loginFormAction" method="performLogin"/>
<transition on="success" to="showLoginResult"/>
<transition on="error" to="enterLoginDetails"/>
</action-state>
<view-state id="showLoginResult" view="showLoginResult"/>
</flow>
Code:
public class LoginFormAction extends FormAction {
private Authenticator authenticator;
public LoginFormAction(Authenticator authenticator) {
this.authenticator = authenticator;
}
public Event performLogin(RequestContext context) {
try {
Credentials credentials = (Credentials)getFormObject(context);
authenticator.authenticate(credentials);
return success();
} catch (InvalidCredentialsException e) {
getFormErrors(context).reject("invalid.credentials");
return error();
}
}
}
Hopefully this gets the general idea/pattern across. The reference manual and FormAction JavaDoc API would be another good resource.