private static GrailsDomainClass getDomainClass(Object instance) {
    GrailsDomainClass domainClass =
        GrailsMetaClassUtils.getPropertyIfExists(
            instance, GrailsDomainClassProperty.DOMAIN_CLASS, GrailsDomainClass.class);
    if (domainClass == null) {
      GrailsWebRequest webRequest = GrailsWebRequest.lookup();
      if (webRequest != null) {
        ApplicationContext applicationContext = webRequest.getApplicationContext();

        GrailsApplication grailsApplication =
            applicationContext.containsBean(GrailsApplication.APPLICATION_ID)
                ? applicationContext.getBean(
                    GrailsApplication.APPLICATION_ID, GrailsApplication.class)
                : null;
        if (grailsApplication != null) {
          domainClass =
              (GrailsDomainClass)
                  grailsApplication.getArtefact(
                      DomainClassArtefactHandler.TYPE, instance.getClass().getName());
        }
      }
    }

    return domainClass;
  }
  @Override
  protected View createFallbackView(String viewName) throws Exception {
    GrailsWebRequest webRequest = GrailsWebRequest.lookup();

    String[] viewNameParts = splitViewName(viewName);
    if (viewNameParts.length == 1) {
      viewName = WebUtils.addViewPrefix(viewName, webRequest.getControllerName());
      viewNameParts = splitViewName(viewName);
    }

    View v = scaffoldedViews.get(viewName);
    if (v == null) {
      GrailsDomainClass domainClass = scaffoldedDomains.get(viewNameParts[0]);
      if (domainClass != null) {
        String viewCode = null;
        try {
          viewCode = generateViewSource(viewNameParts[1], domainClass);
        } catch (Exception e) {
          log.error("Error generating scaffolded view [" + viewName + "]: " + e.getMessage(), e);
        }
        if (StringUtils.hasLength(viewCode)) {
          v = createScaffoldedView(viewName, viewCode);
          scaffoldedViews.put(viewName, v);
        }
      }
    }
    if (v != null) {
      return v;
    }
    return super.createFallbackView(viewName);
  }
Exemplo n.º 3
0
  private void bindWithRequestAndPropertyValues(
      ServletRequest request, MutablePropertyValues mpvs) {
    GrailsWebRequest webRequest = GrailsWebRequest.lookup((HttpServletRequest) request);
    if (webRequest != null) {
      final ApplicationContext applicationContext = webRequest.getApplicationContext();
      if (applicationContext != null) {
        final Map<String, BindEventListener> bindEventListenerMap =
            applicationContext.getBeansOfType(BindEventListener.class);
        for (BindEventListener bindEventListener : bindEventListenerMap.values()) {
          bindEventListener.doBind(getTarget(), mpvs, getTypeConverter());
        }
      }
    }
    preProcessMutablePropertyValues(mpvs);

    if (request instanceof MultipartHttpServletRequest) {
      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
      bindMultipartFiles(multipartRequest.getFileMap(), mpvs);
    }
    doBind(mpvs);
  }