/**
   * Handles the refresh call by checking the request parameters and delegating out to helper
   * methods.
   *
   * <p>{@inheritDoc}
   */
  @Override
  public ModelAndView refresh(UifFormBase form) {
    HttpServletRequest request = form.getRequest();

    if (request.getParameterMap().containsKey(UifParameters.MESSAGE_TO_DISPLAY)) {
      String messageToDisplay = request.getParameter(UifParameters.MESSAGE_TO_DISPLAY);

      if (StringUtils.isNotBlank(messageToDisplay)) {
        GlobalVariables.getMessageMap()
            .putErrorForSectionId(KRADConstants.GLOBAL_ERRORS, messageToDisplay);
      }
    }

    if (request.getParameterMap().containsKey(UifParameters.REFRESH_STATUS)) {
      String refreshStatus = request.getParameter(UifParameters.REFRESH_STATUS);

      // if the return URL reported an error, do not continue with the refresh call
      if (UifConstants.RefreshStatus.ERROR.equals(refreshStatus)) {
        return getModelAndViewService().getModelAndView(form);
      }
    }

    String refreshCallerType = "";
    if (request.getParameterMap().containsKey(KRADConstants.REFRESH_CALLER_TYPE)) {
      refreshCallerType = request.getParameter(KRADConstants.REFRESH_CALLER_TYPE);
    }

    if (StringUtils.equals(refreshCallerType, UifConstants.RefreshCallerTypes.MULTI_VALUE_LOOKUP)) {
      processMultiValueReturn(form, request);
    }

    if (request.getParameterMap().containsKey(KRADConstants.REFERENCES_TO_REFRESH)) {
      final String referencesToRefresh = request.getParameter(KRADConstants.REFERENCES_TO_REFRESH);

      Runnable runnable =
          new Runnable() {
            @Override
            public void run() {
              ViewLifecycle.getHelper().refreshReferences(referencesToRefresh);
            }
          };

      ViewLifecycle.encapsulateLifecycle(
          form.getView(), form, form.getViewPostMetadata(), null, request, runnable);
    }

    if (request.getParameterMap().containsKey(UifParameters.QUICKFINDER_ID)) {
      String quickfinderId = request.getParameter(UifParameters.QUICKFINDER_ID);

      setFocusJumpFromQuickfinder(form, quickfinderId);

      invokeQuickfinderCallback(form, request, quickfinderId);
    }

    return getModelAndViewService().getModelAndView(form);
  }
  /**
   * Handles the return from a multi-value lookup, processing any select line values and invoking
   * the configured view helper service to create the lines for those values in the model
   * collection.
   *
   * <p>There are two supported strategies for returning the selected lines. One, if the lookup view
   * and the caller are within the same application container, Springs input flash map is used. If
   * however, the lookup view is outside the caller, then just a standard request parameter is used.
   *
   * @param form form instance containing the model data
   * @param request http request object being handled
   */
  protected void processMultiValueReturn(final UifFormBase form, HttpServletRequest request) {
    final String lookupCollectionId = request.getParameter(UifParameters.LOOKUP_COLLECTION_ID);

    final String lookupCollectionName = request.getParameter(UifParameters.LOOKUP_COLLECTION_NAME);
    if (StringUtils.isBlank(lookupCollectionName)) {
      throw new RuntimeException(
          "Lookup collection name is required for processing multi-value lookup results");
    }

    final String multiValueReturnFields =
        request.getParameter(UifParameters.MULIT_VALUE_RETURN_FILEDS);
    String selectedLineValuesParam = request.getParameter(UifParameters.SELECTED_LINE_VALUES);

    String flashMapSelectedLineValues = "";
    if (RequestContextUtils.getInputFlashMap(request) != null) {
      flashMapSelectedLineValues =
          (String)
              RequestContextUtils.getInputFlashMap(request).get(UifParameters.SELECTED_LINE_VALUES);
    }

    if (!StringUtils.isBlank(flashMapSelectedLineValues)) {
      selectedLineValuesParam = flashMapSelectedLineValues;
    }

    final String selectedLineValues = selectedLineValuesParam;

    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            // invoked view helper to populate the collection from lookup results
            ViewLifecycle.getHelper()
                .processMultipleValueLookupResults(
                    form,
                    lookupCollectionId,
                    lookupCollectionName,
                    multiValueReturnFields,
                    selectedLineValues);
          }
        };

    ViewLifecycle.encapsulateLifecycle(
        form.getView(), form, form.getViewPostMetadata(), null, request, runnable);
  }
  /**
   * Retrieves the configured focus id and jump id for the quickfinder from the post metadata, and
   * sets those values onto the form for the view rendering.
   *
   * @param form form instance containing the model data
   * @param quickfinderId id for the quickfinder component that triggered the lookup we are
   *     returning from
   */
  protected void setFocusJumpFromQuickfinder(UifFormBase form, String quickfinderId) {
    String focusId =
        (String)
            form.getViewPostMetadata()
                .getComponentPostData(
                    quickfinderId, UifConstants.PostMetadata.QUICKFINDER_FOCUS_ID);
    if (StringUtils.isNotBlank(focusId)) {
      form.setFocusId(focusId);
    }

    String jumpToId =
        (String)
            form.getViewPostMetadata()
                .getComponentPostData(
                    quickfinderId, UifConstants.PostMetadata.QUICKFINDER_JUMP_TO_ID);
    if (StringUtils.isNotBlank(jumpToId)) {
      form.setJumpToId(jumpToId);
    }
  }
 private void changeTheme(UifFormBase form) {
   String theme = ((KradSampleAppForm) form).getThemeName();
   if (theme != null) {
     ViewTheme newTheme =
         (ViewTheme) (KRADServiceLocatorWeb.getDataDictionaryService().getDictionaryBean(theme));
     if (newTheme != null) {
       form.getView().setTheme(newTheme);
     }
   }
 }
 /**
  * Changes the view to readOnly and returns.
  *
  * @param uifForm
  * @param result
  * @param request
  * @param response
  * @return readOnly View
  */
 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=makeReadOnly")
 public ModelAndView makeReadOnly(
     @ModelAttribute("KualiForm") UifFormBase uifForm,
     BindingResult result,
     HttpServletRequest request,
     HttpServletResponse response) {
   // set View to readOnly
   uifForm.getView().setReadOnly(true);
   return getUIFModelAndView(uifForm);
 }
  /**
   * Retrieves post metadata for the quickfinder component with the given id and if a callback
   * method has been configured, invokes that callback method.
   *
   * @param form form instance containing the model data
   * @param request http request object being handled
   * @param quickfinderId id for the quickfinder component that triggered the lookup we are
   *     returning from
   */
  protected void invokeQuickfinderCallback(
      UifFormBase form, final HttpServletRequest request, final String quickfinderId) {
    String callbackMethodToCall =
        (String)
            form.getViewPostMetadata()
                .getComponentPostData(
                    quickfinderId, UifConstants.PostMetadata.QUICKFINDER_CALLBACK_METHOD_TO_CALL);
    MethodInvokerConfig callbackMethod =
        (MethodInvokerConfig)
            form.getViewPostMetadata()
                .getComponentPostData(
                    quickfinderId, UifConstants.PostMetadata.QUICKFINDER_CALLBACK_METHOD);

    if (StringUtils.isBlank(callbackMethodToCall) && (callbackMethod == null)) {
      return;
    }

    if (callbackMethod == null) {
      callbackMethod = new MethodInvokerConfig();
    }

    // get additional parameters to be passed to the callback method
    Map<String, String> callbackContext =
        (Map<String, String>)
            form.getViewPostMetadata()
                .getComponentPostData(
                    quickfinderId, UifConstants.PostMetadata.QUICKFINDER_CALLBACK_CONTEXT);

    // if target class or object not set, use view helper service
    if ((callbackMethod.getTargetClass() == null) && (callbackMethod.getTargetObject() == null)) {
      callbackMethod.setTargetObject(form.getViewHelperService());
    }

    callbackMethod.setTargetMethod(callbackMethodToCall);

    Object[] arguments = new Object[3];
    arguments[0] = form;
    arguments[1] = quickfinderId;
    arguments[2] = callbackContext;
    callbackMethod.setArguments(arguments);

    final MethodInvokerConfig methodToInvoke = callbackMethod;

    Runnable runnable =
        new Runnable() {
          @Override
          public void run() {
            try {
              methodToInvoke.prepare();
              methodToInvoke.invoke();
            } catch (Exception e) {
              throw new RuntimeException(
                  "Error invoking callback method for quickfinder: " + quickfinderId, e);
            }
          }
        };

    ViewLifecycle.encapsulateLifecycle(
        form.getView(), form, form.getViewPostMetadata(), null, request, runnable);
  }
  /** Adds errors to fields defined in the validationMessageFields array */
  @RequestMapping(method = RequestMethod.POST, params = "methodToCall=addStandardSectionsErrors")
  public ModelAndView addStandardSectionsErrors(
      @ModelAttribute("KualiForm") UifFormBase form,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response) {
    GlobalVariables.getMessageMap()
        .putError("Demo-ValidationMessages-Section1", "errorSectionTest");
    GlobalVariables.getMessageMap()
        .putError("Demo-ValidationMessages-Section2", "errorSectionTest");

    Set<String> inputFieldIds = form.getViewPostMetadata().getInputFieldIds();
    for (String id : inputFieldIds) {
      if (form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH)
          != null) {
        String key =
            (String)
                form.getViewPostMetadata().getComponentPostData(id, UifConstants.PostMetadata.PATH);
        GlobalVariables.getMessageMap().putError(key, "error1Test");
      }
    }

    return getUIFModelAndView(form);
  }
Example #8
0
 @Override
 public void postBind(HttpServletRequest request) {
   super.postBind(request);
 }
  /**
   * Builds the incident report model and view from the request that threw the exception
   *
   * @param request - the request
   * @param response - the response
   * @param handler - the current handler when the exception occurred
   * @param ex - the exception
   * @return the incident report model and view
   * @see
   *     org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
   */
  @Override
  public ModelAndView resolveException(
      HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    LOG.error("The following error was caught by the UifHandlerExceptionResolver : ", ex);

    // log exception
    LOG.error(ex.getMessage(), ex);

    String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER);
    String incidentViewId = "";

    UifFormBase form = (UifFormBase) request.getAttribute(UifConstants.REQUEST_FORM);
    if (form instanceof DocumentFormBase) {
      if (((DocumentFormBase) form).getDocument() != null) {
        incidentDocId = ((DocumentFormBase) form).getDocument().getDocumentNumber();
      }
      incidentViewId = ((DocumentFormBase) form).getViewId();
    }

    if (GlobalVariables.getUifFormManager() != null) {
      GlobalVariables.getUifFormManager().removeSessionForm(form);
    }

    UserSession userSession =
        (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
    IncidentReportForm incidentReportForm = new IncidentReportForm();
    incidentReportForm.setSessionId(request.getSession().getId());

    // Set the post url map to the incident report controller and not
    // the one the exception occurred on
    String postUrl = request.getRequestURL().toString();
    postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport";
    incidentReportForm.setFormPostUrl(postUrl);

    incidentReportForm.setException(ex);
    incidentReportForm.setIncidentDocId(incidentDocId);
    incidentReportForm.setIncidentViewId(incidentViewId);
    incidentReportForm.setController(handler.getClass().toString());

    if (userSession != null) {
      incidentReportForm.setUserId(userSession.getPrincipalId());
      incidentReportForm.setUserName(userSession.getPrincipalName());
      incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress());
    }

    incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment());
    incidentReportForm.setViewId("Uif-IncidentReportView");

    if (form != null) {
      incidentReportForm.setAjaxRequest(form.isAjaxRequest());
    } else {
      String ajaxRequestParm = request.getParameter(UifParameters.AJAX_REQUEST);
      if (StringUtils.isNotBlank(ajaxRequestParm)) {
        incidentReportForm.setAjaxRequest(Boolean.parseBoolean(ajaxRequestParm));
      }
    }

    // Set the view object
    incidentReportForm.setView(getViewService().getViewById("Uif-IncidentReportView"));

    // Set the ajax return type
    incidentReportForm.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATEVIEW.getKey());

    ModelAndView modelAndView = getModelAndViewService().getModelAndView(incidentReportForm, "");
    try {
      getModelAndViewService().prepareView(request, modelAndView);
    } catch (Exception e) {
      LOG.error("An error stopped the incident form from loading", e);
    }

    return modelAndView;
  }