protected function handleMetaUi(array $data, $annotation, $targetView, Request $request = null)
    {
        // check if a @ServeUi definition exists on action's annotations
        if (empty($annotation)) {
            return $targetView; // @serveUi annotation not found, just return to break ui handling
        }

        // prepare annotation object
        $annotation->prepare();

        // getting configuration
        $metaPath    = $this->config->get('app.meta_dir');
        $elementName = $annotation->name;
        $metaFile    = $annotation->metaFile;
        $attributes  = $annotation->attributes;
        $layout      = $annotation->layout;

        // setting uiEngine Object
        // if any layout wasn't specified on action's annotation
        if (empty($layout)) {
            // read defaults bundles from configuration for desktop & mobile platform
            if ($request->isMobile()) {
                if ($request->isIpad()) {
                    // for ipad device
                    $layout = $this->config->get('layout.mobile');
                } else {
                    $layout = $this->config->get('layout.mobile');
                }
            } else {
                $layout = $this->config->get('layout.default');
            }
        }
        //var_dump($layout); die;
        //$this->uiEngine->setBundleExtensionDir();
        $this->uiEngine->setTargetBundle($layout);
        $this->uiEngine->setMetaFile($metaPath . DS . $annotation->metaFile);

        // tell to uiEngine object build the ui requested
        $elementData = array();
        if (array_key_exists($elementName, $data) && is_array($data[$elementName])) {
            $elementData = $data[$elementName];
        }

        $element = $this->uiEngine->build($elementData, $attributes);
        //$element->setAttribute($attributes);

        if (! empty($annotation->id)) {
            $element->setId($annotation->id);
        }

        $elementType = $element->getXtype();
        $elementId = $element->getId();
        $elementCollection = new \StdClass();
        $elementCollection->$elementId = $element;

        $targetView->assign($elementType, $elementCollection);

        $template = empty($targetView) ? $element->getXtype() . '_page' : $element->getXtype();

        //var_dump($template, file_exists($template), $this->config->get('templating.default_engine'));
        try {
            // creating a new view object
            $view = $this->createView($template, $data);
            $view->assign($element->getXtype(), $element);

            // if the target view was not defined before return the new view object created.
            if (empty($targetView)) {
                return $view;
            }

            // a target view exists, just set the generated ui to target view
            $targetView->setUiElement($element->getId(), $view->getOutput());
            $elementObject = new \StdClass();
            $elementObject->$elementId = $element;
            $targetView->set($element->getXtype(), $elementObject);
        } catch (\Exception $e) {
            // skip exception for template not found
            if ($e->getCode() !== 404) {
                throw $e;
            }
        }

        return $targetView;
    }