Since this isn't as clear as it could be, here's an example for anyone who
cares:
> (this class adds or updates a bulletin on a message board; all data access
> goes through a central service called the "DataStore")
>
> public final class UpdateBulletinAction extends Action {
>
> public ActionForward execute(ActionMapping mapping, ActionForm form,
> HttpServletRequest request, HttpServletResponse response)
> throws Exception {
>
> ActionErrors errors = new ActionErrors();
>
> DynaActionForm dynaForm = (DynaActionForm) form;
> UserView user =
> (UserView)request.getSession().getAttribute(Constants.USER_KEY);
>
> if (((String)((DynaActionForm)form).get ("id")).equals ("0")) { //
> ID = 0 means we're adding a bulletin
> try {
> BulletinView bv = DataStore.getNewBulletinView();
> bv.setAccessLevel ((String)dynaForm.get
> ("accessLevel"));
> bv.setMessage ((String)dynaForm.get("message"));
> DataStore.addBulletinView (bv);
> } catch (ViewRecAddException e) {
> servlet.log("An error occurred while user " +
> user.getName() + " was adding a bulletin:\n" +
> e.toString());
> e.printStackTrace();
> errors.add(ActionErrors.GLOBAL_ERROR,
> new ActionError("error.databaseerror"));
> }
> } else { // Since we have an ID, we're updating a bulletin
> try {
> BulletinView bv =
> DataStore.getBulletinViewById((String)dynaForm.get("id"));
> bv.setAccessLevel
((String)dynaForm.get("accessLevel"));
> bv.setMessage ((String)dynaForm.get("message"));
> DataStore.updateBulletinView (bv);
> } catch (ViewRecLoadException e) {
> servlet.log("An error occurred while trying to get
> bulletin ID=" + (String)dynaForm.get("id") + " for update by user " +
> user.getName() +
> ":\n" + e.toString());
> e.printStackTrace();
> errors.add(ActionErrors.GLOBAL_ERROR,
> new ActionError("error.databaseerror"));
> } catch (ViewRecUpdateException e) {
> servlet.log("An error occurred while user " +
> user.getName() + " was updating bulletin with ID=" +
> (String)dynaForm.get("id") +
> ":\n" + e.toString());
> e.printStackTrace();
> errors.add(ActionErrors.GLOBAL_ERROR,
> new ActionError("error.databaseerror"));
> }
> if (!errors.isEmpty()) {
> saveErrors(request, errors);
> return (new ActionForward(mapping.getInput()));
> }
>
> return (mapping.findForward("success"));
> }
> }
>
> so to refer to a property of a DynaActionForm within an action, you do
> something like
>
> DynaActionFrom dynaForm = (DynaActionForm) form;
> // variable "form" comes from method execute's signature
>
> someVariable = (className)dynaForm.get("propertyName");
> // to get the property; DynaActionForm.get(String property) returns an
Object, so you have to cast it
>
> dynaForm.set("propertyName", someVariable);
> // to set the property; the class of the second parameter is, again,
"Object"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]