Example #1
0
 /**
  * Convenience method for removing the obsolete form bean.
  *
  * @param mapping The ActionMapping used to select this instance
  * @param request The HTTP request we are processing
  */
 protected void removeFormBean(ActionMapping mapping, HttpServletRequest request) {
   // Remove the obsolete form bean
   if (mapping.getAttribute() != null) {
     if ("request".equals(mapping.getScope())) {
       request.removeAttribute(mapping.getAttribute());
     } else {
       HttpSession session = request.getSession();
       session.removeAttribute(mapping.getAttribute());
     }
   }
 }
Example #2
0
  /**
   * 获得FormBean
   *
   * @param mapping
   * @param request
   * @return
   */
  protected ActionForm getActionForm(ActionMapping mapping, HttpServletRequest request) {
    ActionForm actionForm = null;

    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
      if ("request".equals(mapping.getScope())) {
        actionForm = (ActionForm) request.getAttribute(mapping.getAttribute());
      } else {
        HttpSession session = request.getSession();
        actionForm = (ActionForm) session.getAttribute(mapping.getAttribute());
      }
    }

    return actionForm;
  }
Example #3
0
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if business logic throws an exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Extract attributes we will need
    User user = null;

    // Validate the request parameters specified by the user
    ActionMessages errors = new ActionMessages();
    String username = (String) PropertyUtils.getSimpleProperty(form, "username");
    String password = (String) PropertyUtils.getSimpleProperty(form, "password");
    UserDatabase database =
        (UserDatabase) servlet.getServletContext().getAttribute(Constants.DATABASE_KEY);
    if (database == null)
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.database.missing"));
    else {
      user = getUser(database, username);
      if ((user != null) && !user.getPassword().equals(password)) user = null;
      if (user == null)
        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.password.mismatch"));
    }

    // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {
      saveErrors(request, errors);
      return (mapping.getInputForward());
    }

    // Save our logged-in user in the session
    HttpSession session = request.getSession();
    session.setAttribute(Constants.USER_KEY, user);
    if (log.isDebugEnabled()) {
      log.debug(
          "LogonAction: User '" + user.getUsername() + "' logged on in session " + session.getId());
    }

    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
      if ("request".equals(mapping.getScope())) request.removeAttribute(mapping.getAttribute());
      else session.removeAttribute(mapping.getAttribute());
    }

    // Forward control to the specified success URI
    return (mapping.findForward("success"));
  }
 private ActionForm createNewActionForm(ActionMapping mapping, HttpServletRequest request) {
   String name = mapping.getName();
   FormBeanConfig config = moduleConfig.findFormBeanConfig(name);
   if (config == null) {
     log.warn("No FormBeanConfig found under '" + name + "'");
     return (null);
   }
   ActionForm instance = RequestUtils.createActionForm(config, servlet);
   if ("request".equals(mapping.getScope())) {
     request.setAttribute(mapping.getAttribute(), instance);
   } else {
     HttpSession session = request.getSession();
     session.setAttribute(mapping.getAttribute(), instance);
   }
   return instance;
 }
Example #5
0
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws IOException, ServletException {
    String target = "success";
    String strTyp =
        (request.getParameter("reqtyp") != null) ? request.getParameter("reqtyp").trim() : "New";
    //// System.out.println("Request Type in test data "+strTyp);
    // String strTestTyp = (request.getParameter("testtyp")!=null) ?
    // request.getParameter("testtyp").trim() : "Digital";
    try {
      if (strTyp.equalsIgnoreCase("New")) {
        form = buildUserForm();
      } else {
        String strTid =
            (request.getParameter("tstid") != null) ? request.getParameter("tstid").trim() : "0";
        if (Integer.parseInt(strTid.trim()) <= 0) {
          form = buildUserForm();
        } else {
          form = buildUserDetailForm(Integer.parseInt(strTid.trim()), request);
        }
      }
      if ("request".equals(mapping.getScope())) {
        request.setAttribute(mapping.getAttribute(), form);
      } else {
        HttpSession session = request.getSession();
        session.setAttribute(mapping.getAttribute(), form);
      }
    } catch (Exception e) {
      target = new String("failure");
      ActionErrors errors = new ActionErrors();

      errors.add(
          ActionErrors.GLOBAL_ERROR, new ActionError("errors.database.error", e.getMessage()));

      // Report any errors
      if (!errors.isEmpty()) {

        saveErrors(request, errors);
      }
    }

    return (mapping.findForward(target));
  }
  /** Hooks into populate process to call form populate method if form is an instanceof PojoForm. */
  @Override
  protected void processPopulate(
      HttpServletRequest request,
      HttpServletResponse response,
      ActionForm form,
      ActionMapping mapping)
      throws ServletException {
    if (form instanceof KualiForm) {
      // Add the ActionForm to GlobalVariables
      // This will allow developers to retrieve both the Document and any
      // request parameters that are not
      // part of the Form and make them available in ValueFinder classes
      // and other places where they are needed.
      KNSGlobalVariables.setKualiForm((KualiForm) form);
    }

    // if not PojoForm, call struts populate
    if (!(form instanceof PojoForm)) {
      super.processPopulate(request, response, form, mapping);
      return;
    }

    final String previousRequestGuid =
        request.getParameter(
            KualiRequestProcessor.PREVIOUS_REQUEST_EDITABLE_PROPERTIES_GUID_PARAMETER_NAME);

    ((PojoForm) form).clearEditablePropertyInformation();
    ((PojoForm) form).registerStrutsActionMappingScope(mapping.getScope());

    String multipart = mapping.getMultipartClass();
    if (multipart != null) {
      request.setAttribute(Globals.MULTIPART_KEY, multipart);
    }

    form.setServlet(this.servlet);
    form.reset(mapping, request);

    ((PojoForm) form).setPopulateEditablePropertiesGuid(previousRequestGuid);
    // call populate on ActionForm
    ((PojoForm) form).populate(request);
    request.setAttribute("UnconvertedValues", ((PojoForm) form).getUnconvertedValues().keySet());
    request.setAttribute("UnconvertedHash", ((PojoForm) form).getUnconvertedValues());
  }
 /* (non-Javadoc)
  * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  */
 public ActionForward execute(
     ActionMapping mapping, ActionForm form, HttpServletRequest req, HttpServletResponse res)
     throws Exception {
   String title = req.getParameter("search_title");
   String content = req.getParameter("search_content");
   int page = ParamUtil.get(req, "page", 0);
   try {
     if (mapping.getAttribute() != null) {
       if ("request".equals(mapping.getScope())) {
         req.setAttribute(mapping.getAttribute(), form);
       } else {
         req.getSession().setAttribute(mapping.getAttribute(), form);
       }
     }
     req.setAttribute(
         "result",
         InformationUtil.search(title, content, EcardConstants.INFORMATION_TUTORIAL_TYPE, page));
     return mapping.findForward("portlet.ecardtutorial.search_result");
   } catch (PortalException pe) {
     req.setAttribute(PageContext.EXCEPTION, pe);
     return mapping.findForward(Constants.COMMON_ERROR);
   }
 }
  /**
   * Process the specified HTTP request, and create the corresponding HTTP response (or forward to
   * another web component that will create it). Return an <code>ActionForward</code> instance
   * describing where and how control should be forwarded, or <code>null</code> if the response has
   * already been completed.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @exception Exception if the application business logic throws an exception
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // Extract attributes we will need
    Locale locale = getLocale(request);
    MessageResources messages = getResources(request);
    HttpSession session = request.getSession();
    String action = request.getParameter("action");
    if (action == null) {
      action = "Create";
    }
    String host = request.getParameter("host");
    if (log.isDebugEnabled()) {
      log.debug("EditSubscriptionAction:  Processing " + action + " action");
    }

    // Is there a currently logged on user?
    User user = (User) session.getAttribute(Constants.USER_KEY);
    if (user == null) {
      if (log.isTraceEnabled()) {
        log.trace(" User is not logged on in session " + session.getId());
      }
      return (mapping.findForward("logon"));
    }

    // Identify the relevant subscription
    Subscription subscription = user.findSubscription(request.getParameter("host"));
    if ((subscription == null) && !action.equals("Create")) {
      if (log.isTraceEnabled()) {
        log.trace(" No subscription for user " + user.getUsername() + " and host " + host);
      }
      return (mapping.findForward("failure"));
    }
    if (subscription != null) {
      session.setAttribute(Constants.SUBSCRIPTION_KEY, subscription);
    }

    // Populate the subscription form
    if (form == null) {
      if (log.isTraceEnabled()) {
        log.trace(" Creating new SubscriptionForm bean under key " + mapping.getAttribute());
      }
      form = new SubscriptionForm();
      if ("request".equals(mapping.getScope())) {
        request.setAttribute(mapping.getAttribute(), form);
      } else {
        session.setAttribute(mapping.getAttribute(), form);
      }
    }
    SubscriptionForm subform = (SubscriptionForm) form;
    subform.setAction(action);
    if (!action.equals("Create")) {
      if (log.isTraceEnabled()) {
        log.trace(" Populating form from " + subscription);
      }
      try {
        PropertyUtils.copyProperties(subform, subscription);
        subform.setAction(action);
      } catch (InvocationTargetException e) {
        Throwable t = e.getTargetException();
        if (t == null) t = e;
        log.error("SubscriptionForm.populate", t);
        throw new ServletException("SubscriptionForm.populate", t);
      } catch (Throwable t) {
        log.error("SubscriptionForm.populate", t);
        throw new ServletException("SubscriptionForm.populate", t);
      }
    }

    // Forward control to the edit subscription page
    if (log.isTraceEnabled()) {
      log.trace(" Forwarding to 'success' page");
    }
    return (mapping.findForward("success"));
  }