处理参数绑定错误

@param be  绑定异常
@param mvc mvc

@return mvc
196430
private ModelAndView buildBizErrors(BindException be, ModelAndView mvc) {
        Map<String, Object> paramErrors = new HashMap<String, Object>();
        Object o = be.getTarget();
        for (Object error : be.getAllErrors()) {
            if (error instanceof FieldError) {
                FieldError fe = (FieldError) error;
                String field = fe.getField();
                Field oField = null;
                try {
                    oField = o.getClass().getField(field);
                } catch (NoSuchFieldException e) {
                    // TODO: omit handle exception
                }
                if (oField == null) {
                    paramErrors.put(field, GlobalResponseStatusMsg.PARAM_BIND_ERROR.getMessage()
                            .getMessage());
                } else if (oField.getType().equals(Integer.class)
                        || oField.getType().equals(Long.class)
                        || oField.getType().equals(Short.class)) {
                    paramErrors.put(field, GlobalResponseStatusMsg.PARAM_BIND_ERROR.getMessage()
                            .getMessage());
                } else if (oField.getType().equals(Float.class)
                        || oField.getType().equals(Double.class)) {
                    paramErrors.put(field, GlobalResponseStatusMsg.PARAM_BIND_ERROR.getMessage()
                            .getMessage());
                } else {
                    paramErrors.put(field, GlobalResponseStatusMsg.PARAM_BIND_ERROR.getMessage()
                            .getMessage());
                }
            }
        }

        return buildBizError(mvc, paramErrors);
    }
358085
function initModelNew (args) {
    var controller = this
    var model = this.model
    // if model/controller does not have form then cannot create new controller
    if (!this.form) {
        return
    }
    // create path if it does not exist
    if (!this.paths['/new']) {
        this.paths['/new'] = {}
    }
    // get accountId column
    var accountIdColumn = model.columnName('accountId') 
    // set role to authenticated if model requires account id
    var role = args.defaultRole || (accountIdColumn && model.columns[accountIdColumn].null === false ? 'authenticated' : 'all')
    // form inputs
    var input = {
        redirect: 'query.redirect',
    }
    // input may include pre-filled form values
    input[model.name] = 'query.'+model.name
    // add handler for GET /new
    this.paths['/new'].get = [
        {
            before: function (args) {
                return newInstance(controller, args)
            },
            input: input,
            method: function (args) {
                return {form: args.form}
            },
            methodName: 'new',
            role: role,
            template: 'instance',
        },
    ]
}
1178768
function View(primaryModel, relatedModels, attributes) {
  if (false === (this instanceof View)) throw new Error('new operator required');
  if (!(primaryModel instanceof Model)) throw new Error('argument must be a Model');
  if (typeof relatedModels != 'object') throw new Error('object expected');
  if (!(attributes instanceof Array)) throw new Error('array of attributes expected');
  this.primaryModel = primaryModel;
  this.relatedModels = relatedModels;
  this.attributes = attributes;
  var id = new Attribute('id', 'ID');
  id.model = primaryModel;
  this.attributes.unshift(id);

  /**
   * Make sure relatedModels valid
   */
  for (var relatedModel in relatedModels) {
    if (relatedModels.hasOwnProperty(relatedModel)) {
      var obj = relatedModels[relatedModel];
      //console.log('relatedModel ' + relatedModel);
      //console.log('obj ' + JSON.stringify(obj));
      if (typeof obj != 'object') throw new Error('relatedModel key values expect object');
      if (obj.id === undefined) throw new Error('relatedModel key values expect object with id key');
      if (obj.model === undefined) throw new Error('relatedModel key values expect object with model key');
      if (!(obj.id instanceof Attribute)) throw new Error('relatedModel id must be a Attribute');
      if (!(obj.model instanceof Model)) throw new Error('relatedModel model must be a Model');
    }
  }
  /**
   * Check attributes
   */
  for (var i = 0; i < attributes.length; i++) {
    var attribute = attributes[i];
    if (!(attribute instanceof Attribute)) throw new Error('attribute array must contain Attributes');
    if (!(attribute.model instanceof Model)) {
      throw new Error('attribute array must contain Attributes with model references');
    }

  }
}
1282333
public function selectLayoutBasedOnRoute(MvcEvent $e)
    {
        /** @var \Zend\Mvc\Application $app */
        $app    = $e->getParam('application');
        $sm     = $app->getServiceManager();
        $config = $sm->get('config');

        if (false === $config['zfcadmin']['use_admin_layout']) {
            return;
        }

        $match      = $e->getRouteMatch();
        $controller = $e->getTarget();
        if (!($match instanceof V2RouteMatch || $match instanceof V3RouteMatch)
            || 0 !== strpos($match->getMatchedRouteName(), 'zfcadmin')
            || $controller->getEvent()->getResult()->terminate()
        ) {
            return;
        }

        $layout     = $config['zfcadmin']['admin_layout_template'];
        $controller->layout($layout);
    }
1212572
public function bootstrap()
    {
        $serviceManager = $this->serviceManager;
        $events         = $this->getEventManager();

        $events->attach($serviceManager->get('DispatchListener'));
        $events->attach($serviceManager->get('SendResponseListener'));

        // Setup MVC Event
        $this->event = $event  = new MvcEvent();
        $event->setTarget($this);
        $event->setApplication($this)
              ->setRequest($this->getRequest())
              ->setResponse($this->getResponse())
              ->setRouter($serviceManager->get('Router'));

        // Trigger bootstrap events
        $events->trigger(MvcEvent::EVENT_BOOTSTRAP, $event);
        return $this;
    }
1138686
private void invokeActionMethod() throws ActionException {
		Object returnValue = null;
		Class<?>[] parameterTypes = this.method.getParameterTypes();
		try {
			returnValue = this.method.invoke(action, paramTypesToObj(parameterTypes));
		} catch(InvocationTargetException te) {
			throw new ActionException(te.getCause());
		} catch (Exception e) {
			throw new ActionException("Invoke action method error!", e);
		}
		
		//对于带有返回值的Action方法，执行Render
		if(null != returnValue) {
			if(false == (returnValue instanceof View)) {
				//将未识别响应对象包装为View
				returnValue = DefaultView.wrap(returnValue);
			}
			((View) returnValue).render();
		}
	}
889251
@Override
    public void onCreate() {
        super.onCreate();

        graphMonitor = new Graph.Monitor() {
            @Override
            public void onInject(Object target) {
                if (controller != null && target == MvcService.this) {
                    controller.view = MvcService.this;
                }
            }

            @Override
            public void onRelease(Object target) {

            }
        };
        Mvc.graph().registerMonitor(graphMonitor);

        if (getControllerClass() != null) {
            try {
                controller = Mvc.graph().reference(getControllerClass(), null);
            } catch (CircularDependenciesException e) {
                e.printStackTrace();
            } catch (ProvideException e) {
                e.printStackTrace();
            } catch (ProviderMissingException e) {
                throw new IllegalStateException("Unable to inject "
                        + getControllerClass().getName() + ".\n" + e.getMessage(), e);
            }
        }

        Mvc.graph().inject(this);

        eventRegister = new EventRegister(this);
        eventRegister.registerEventBuses();
    }
622417
public static Object create(ActionParameter argument, Context context,
                                ParameterFactories engine) {
        RouteParameterHandler handler = BINDINGS.get(argument.getSource());
        if (handler != null) {
            return handler.create(argument, context, engine);
        } else {
            LoggerFactory.getLogger(Bindings.class).warn("Unsupported route parameter in method : {}",
                    argument.getSource().name());
            return null;
        }
    }
900080
@Deprecated
    public MethodBinding getAction() {
        MethodBinding result = null;
        MethodExpression me;

        if (null != (me = getActionExpression())) {
            result = new MethodBindingMethodExpressionAdapter(me);
        }
        return result;
    }
897564
public Response bind(String name, Object model) {
        getLocals().put(name, model);

        return this;
    }
266658
function()
	{
		var model, attr, result, result2, modelPathArray, i, ret, modelArgs;
		var dataBindAttr = this.element.getAttribute(settings.DATA_BIND_ATTR);
		var modelName;

		this._modelBindersMap = new BinderMap();

		if(dataBindAttr == null) return;

		var parsedBindings = matchBindings(dataBindAttr);

		if(process.env.NODE_ENV !== 'production')
		{
			if(parsedBindings.error)
			{
				if(this.element && this.element.parentNode)
				{
					this.element.parentNode.scrollIntoView();
					this.element.parentNode.style.outline = '2px dashed red';
				}
				console.error('Error parsing binding expression: ');
				console.error(parsedBindings.error);
				console.log(this.element);
			}
		}

		if(parsedBindings.match && parsedBindings.match.bindings)
		{
			parsedBindings = parsedBindings.match.bindings;

			for(var i = 0, l = parsedBindings.length; i < l; i++)
			{
				var parsedBinding = parsedBindings[i];

				if(parsedBinding.binder === 'each')
				{
					if(process.env.NODE_ENV !== 'production')
					{
						if(this._collectionBinder)
						{
							if(this.element && this.element.parentNode)
							{
								this.element.parentNode.scrollIntoView();
								this.element.parentNode.style.outline = '2px dashed red';
							}
							console.error('You cannot have two :each binders on the same element');
							console.log(this.element);
						}
					}
					if(!this.options.isBoundView)
					{
						var animate = null;
						var keyProp = null;
						var alias = null;

						if(parsedBinding.operators)
						{
							for(var j = 0, k = parsedBinding.operators.length; j < k; j++)
							{
								var operator = parsedBinding.operators[j];
								if(operator.args.length >= 1 && operator.args[0].type === 'ident')
								{
									if(operator.name === 'animate') animate = operator.args[0].value;
									if(operator.name === 'key') keyProp = operator.args[0].value;
									if(operator.name === 'as') alias = operator.args[0].value;
								}
							}
						}

						this._collectionBinder = new CollectionBinder({
							view: this,
							keyPath: parsedBinding.keyPath,
							collectionArgs: parsedBinding.modelArgs,
							animate: animate,
							keyProp: keyProp
						});

						if(alias)
						{
							this._itemAlias = alias;
						}
						else this._itemAlias = settings.defaultItemAlias;
					}
				}
				else
				{
					if(!(parsedBinding.binder in View.binders)) break;

					var scope = this.scope;
					var isIdent = function(v){ return v != null && v.type === 'ident'; }
					var identToParser = function(v)
					{
						if(scope[v.value]) return { fn: scope[v.value], args: [] };
						else if(View.helpers[v.value]) return { fn: View.helpers[v.value], args: [] };
					}
					var argToValue = function(v)
					{
						return v.value;
					}
					var isNotNull = function(v)
					{
						return v != null;
					}

					var binderConfig = {
						view: this,
						element: this.element,
						params: parsedBinding.binderArgs.filter(isNotNull),
						keyPath: parsedBinding.keyPath,
						modelArgs: parsedBinding.modelArgs.filter(isNotNull),
						formatters: [],
						parsers: [],
						dispatch: null,
						// dispatchNamedParams: ret.dispatchNamedParams,
						eventNames: [],
						eventFilters: null,
						fill: false,
						nopreventdef: false,
						animate: null,
						indexed: false
					};


					for(var j = 0, k = parsedBinding.operators.length; j < k; j++)
					{
						var operator = parsedBinding.operators[j];
						switch(operator.name)
						{
							case 'format':
							case 'f':
								binderConfig.formatters = operator.args.filter(isIdent).map(identToParser);
								break;
							case 'parse':
							case 'p':
								binderConfig.parsers = operator.args.filter(isIdent).map(identToParser);
								break;
							case 'dispatch':
								if(operator.args.length > 0)
								{
									binderConfig.dispatch = operator.args;
								}
								break;
							case 'on':
								if(operator.args.length > 0)
								{
									binderConfig.eventNames = operator.args.filter(isIdent).map(argToValue);
								}
								break;
							case 'evf':
								binderConfig.eventFilters = operator.args.filter(isIdent).map(identToParser);
								break;
							case 'fill':
								binderConfig.fill = true;
								break;
							case 'nopreventdef':
								binderConfig.nopreventdef = true;
								break;
							case 'animate':
								binderConfig.animate = operator.args[0].value;
								break;
						}
					}

					for(var j = binderConfig.formatters.length - 1; j >= 0; j--)
					{
						if(binderConfig.formatters[j].fn.indexed === true) binderConfig.indexed = true;
					}

					var modelBinder = new View.binders[parsedBinding.binder](binderConfig);

					this._modelBindersMap.add(modelBinder);
				}
			}
		}

		// Check for invalid combination of :each and :if binders:
		if(process.env.NODE_ENV !== 'production')
		{
			var ifBinders = this._modelBindersMap.binders.filter(function(binder){ return binder instanceof View.binders.if || binder instanceof View.binders.ifnot; });

			if(this._collectionBinder && ifBinders.length > 0)
			{
				if(this.element && this.element.parentNode)
				{
					this.element.parentNode.scrollIntoView();
					this.element.parentNode.style.outline = '2px dashed red';
				}
				console.error('You cannot combine :each binder with :if binder on the same element');
				console.log(this.element);
			}

			if(ifBinders.length > 2)
			{
				if(this.element && this.element.parentNode)
				{
					this.element.parentNode.scrollIntoView();
					this.element.parentNode.style.outline = '2px dashed red';
				}
				console.error('You cannot combine multiple :if binders on the same element');
				console.log(this.element);
			}
		}

	}
1366163
@Override
	public WebMvcLinkBuilder linkTo(Class<?> controller, Map<String, ?> parameters) {
		return WebMvcLinkBuilder.linkTo(controller, parameters);
	}
384253
public static void showVirtualKeyboard(View view) {
        final Context context = view.getContext();
        final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
40272
public static MvcGraph graph() {
        if (graph == null) {
            graph = new MvcGraph();

            try {
                graph.getRootComponent().register(new Object() {
                    @Provides
                    @EventBusC
                    public EventBus eventBusC() {
                        return new EventBusImpl();
                    }

                    @Provides
                    @EventBusV
                    public EventBus eventBusV() {
                        return new EventBusImpl() {
                            @Override
                            public void post(final Object event) {
                                if (graph.uiThreadRunner.isOnUiThread()) {
                                    postEvent(event);
                                } else {
                                    graph.uiThreadRunner.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            postEvent(event);
                                        }
                                    });
                                }
                            }

                            private void postEvent(Object event) {
                                super.post(event);
                            }
                        };
                    }

                    @Provides
                    public ExecutorService executorService() {
                        return Executors.newFixedThreadPool(10, new ThreadFactory() {
                            @Override
                            public Thread newThread(final Runnable r) {
                                return new Thread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Thread.currentThread().setPriority(Thread.NORM_PRIORITY - 1);
                                        r.run();
                                    }
                                }, "MvcBackgroundThread");
                            }
                        });
                    }
                });
            } catch (ProvideException e) {
                throw new MvcGraphException("Failed to register base Mvc dependencies", e);
            } catch (ProviderConflictException e) {
                throw new MvcGraphException("Failed to register base Mvc dependencies", e);
            }
        }
        return graph;
    }
149554
protected function mvc()
    {
        $request = ServerRequest::fromGlobals();
        $response = new Response();
        $frontController = $this->propagate(new TaoFrontController());
        $frontController($request, $response);
    }
1096944
function onMvcErrorInjectViewModel($e)
    {
        $result = $e->getResult();
        if (!$result instanceof ModelInterface)
            return;

        $model = $e->getViewModel();

        if ($result->terminate()) {
            $e->setViewModel($result);
            return;
        }

        if ($e->getError() && $model instanceof ClearableModelInterface) {
            $model->clearChildren();
        }

        $model->addChild($result);
    }
1092029
function Resolve(context, model) {
    if (model == null) {
        // 清空context
        for (var prop in context) {
            var target = context[prop];
            if (target instanceof view_1.View) {
                var propName = target.PropertyName();
                if (propName) {
                    if (target instanceof text_1.TextView || target instanceof choice_1.ChoiceView) {
                        target.Clear();
                    }
                    else if (target instanceof list_1.ListView) {
                        target.SetData([]);
                    }
                    else {
                        console.warn(propName + " clear failed, missing clear method!");
                    }
                }
            }
        }
        return;
    }
    for (var prop in context) {
        var target = context[prop];
        if (target instanceof view_1.View) {
            var propName = target.PropertyName();
            if (propName) {
                var value = model[propName];
                if (value) {
                    // 注入
                    if (target instanceof text_1.TextView || target instanceof choice_1.ChoiceView) {
                        target.SetValue(value);
                    }
                    else if (target instanceof list_1.ListView && $.isArray(value)) {
                        target.SetData(value);
                    }
                    else {
                        console.warn(propName + " resolve failed, control type is mismatching!");
                    }
                }
                else {
                    console.warn(propName + " resolve failed, value invalid!");
                }
            }
        }
    }
}