For filling our form, we make use of a FormBean, the UserEditForm,
which can be derived directly from org.apache.struts.action.ActionForm.
The FormBean is, in our example, initialized in a simplified manner with
our UserObject, which has previously loaded the data for the key transferred
in the Request from a database.
import java.io.IOException;
import javax.servlet.ServletException;
import com.cc.framework.adapter.struts.ActionContext;
import com.cc.framework.adapter.struts.FWAction;
public class UserEditAction extends FWAction {
/**
* @see com.cc.framework.adapter.struts.FWAction#doExecute(ActionContext)
*/
public void doExecute(ActionContext ctx)
throws IOException, ServletException {
String userId = ctx.request().getParameter("userid");
try {
// Load the User
User user = new User(userId);
user.load();
// Initialise the Form with the User-Data
UserEditForm form = (UserEditForm) ctx.form();
form.setUser(user);
// In our Example we store the UserObject
// in our Session
ctx.session().setAttribute("userobj", user);
}
catch (Throwable t) {
ctx.addGlobalError("Error: ", t);
ctx.forwardByName(Forwards.BACK);
}
// Call the JSP-Page with the Form
ctx.forwardToInput();
}
}
back |
continue to step 4
|