/**
   * 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);
  }
  /**
   * Invoked during the finalize phase to capture state of the component needs to support post
   * operations.
   */
  @Override
  protected void addComponentPostMetadata() {
    super.addComponentPostMetadata();

    Map<String, Map<String, Object>> lookupCriteriaFields =
        ViewLifecycle.getViewPostMetadata().getLookupCriteria();

    Map<String, Object> criteriaAttributes = new HashMap<String, Object>();
    criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.COMPONENT_ID, this.getId());

    if (this.isDisableWildcardsAndOperators()) {
      criteriaAttributes.put(
          UifConstants.LookupCriteriaPostMetadata.DISABLE_WILDCARDS_AND_OPERATORS, true);
    }

    if (this.getRequired()) {
      criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.REQUIRED, true);
    }

    if (this.hasSecureValue()) {
      criteriaAttributes.put(UifConstants.LookupCriteriaPostMetadata.SECURE_VALUE, true);
    }

    ValidCharactersConstraint validCharactersConstraint = this.getValidCharactersConstraint();
    if (validCharactersConstraint != null) {
      criteriaAttributes.put(
          UifConstants.LookupCriteriaPostMetadata.VALID_CHARACTERS_CONSTRAINT,
          validCharactersConstraint);
    }

    lookupCriteriaFields.put(this.getPropertyName(), criteriaAttributes);

    addHiddenComponentPostMetadata(lookupCriteriaFields);
  }
  /**
   * 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);
  }
Ejemplo n.º 4
0
  @Test
  /**
   * Tests rendering on required messages
   *
   * @see KULRICE-7130
   */
  public void testRequiredMessageDisplay() throws Exception {

    // create mock component
    //        View mockView =  mock(View.class);
    //        ViewHelperService mockViewHelperService = mock(ViewHelperService.class);
    //        when(mockView.getViewHelperService()).thenReturn(mockViewHelperService);
    //        when(mockView.copy()).thenReturn(mockView);
    //        when(mockView.clone()).thenReturn(mockView);

    ViewLifecycle.encapsulateLifecycle(
        view,
        null,
        null,
        new Runnable() {
          @Override
          public void run() {
            Object nullModel = null;
            Component mockComponent = mock(Component.class);

            // build asterisk required message and mock label to test rendering
            Label mockLabel = new Label();
            Message message = new Message();
            message.setMessageText("*");
            message.setRender(true);

            FieldBase fieldBase = new FieldBase();
            fieldBase.setFieldLabel(mockLabel);
            fieldBase.setRequired(true);
            fieldBase.setReadOnly(false);

            FieldBase fieldBaseCopy = CopyUtils.copy(fieldBase);
            fieldBaseCopy.performFinalize(nullModel, mockComponent);
            assertTrue(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());

            // required and readonly -  do not render
            fieldBaseCopy = CopyUtils.copy(fieldBase);
            fieldBaseCopy.setReadOnly(true);
            fieldBaseCopy.performFinalize(nullModel, mockComponent);
            assertFalse(fieldBaseCopy.getFieldLabel().isRenderRequiredIndicator());
          }
        });
  }
  /**
   * 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);
  }
Ejemplo n.º 6
0
  /**
   * Retrieves the view singleton from spring that has the given id.
   *
   * @param viewId the unique id for the view
   * @return View instance with the given id
   */
  public View getImmutableViewById(String viewId) {
    String beanName = viewBeanEntriesById.get(viewId);
    if (StringUtils.isBlank(beanName)) {
      throw new DataDictionaryException("Unable to find View with id: " + viewId);
    }

    View view = ddBeans.getBean(beanName, View.class);

    if (UifConstants.ViewStatus.CREATED.equals(view.getViewStatus())) {
      try {
        ViewLifecycle.preProcess(view);
      } catch (IllegalStateException ex) {
        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "preProcess not run due to an IllegalStateException. Exception message: "
                  + ex.getMessage());
        }
      }
    }

    return view;
  }
 /** {@inheritDoc} */
 @Override
 protected void performLifecycleTask() {
   // invoke initialize service hook
   ViewLifecycle.getHelper().performCustomInitialization(getElementState().getElement());
 }