在基于组件的 MVC 中,单个前端控制器将收集、转换和验证请求参数并更新模型值本身,以便您只需要自己担心业务操作。控制器需要如何收集/转换/验证/更新值是在单个位置(视图)中定义的。由于“纯”HTML 不可能实现这一点,因此需要特定的标记语言来实现该目标。对于 JSF 2.0,它是基于 XML (XHTML) 的。您使用 XML 来定义 UI 组件,这些组件又包含有关控制器应如何收集/转换/验证/更新模型值并生成/呈现必要的 HTML 表示的信息。
In request (action) based MVC, a single front controller servlet will delegate to action models based on request URL/params. You work directly with raw HttpServletRequest and HttpServletResponse objects in the action model. You've to write code yourself to gather, convert and validate the request parameters and if necessary update the model values before you can ever invoke the business action.
In component based MVC, a single front controller will gather, convert and validate request parameters and update the model values itself so that you only need to worry about the business action yourself. How the controller needs to gather/convert/validate/update the values is definied in a single place, the view. Since that's not possible with "plain" HTML, a specific markup language is required to achieve the goal. In case of JSF 2.0, that's XML (XHTML) based. You use XML to define UI components which in turn contain information about how the controller should gather/convert/validate/update the model values and generate/render the necessary HTML representation.
Advantages and disadvantages should be clear at this point: With a request based MVC framework you need to write more (boilerplate) code yourself to achieve the goal. However you end up with much more fine grained control over the process and the HTML/CSS/JS output. With a component based MVC framework you don't need to write much code yourself. However you have less fine grained control over the process and the HTML/CSS/JS output. So if you'd like to do things a bit differently than the standard describes and/or the implementation provides, then you'll waste a lot more time in a component based MVC framework when you're not well versed with its ins and outs.
发布评论
评论(1)
在基于请求(操作)的 MVC 中,单个前端控制器 servlet 将根据请求 URL/参数委托给操作模型。您可以直接使用操作模型中的原始
HttpServletRequest
和HttpServletResponse
对象。您必须自己编写代码来收集、转换和验证请求参数,并在必要时更新模型值,然后才能调用业务操作。在基于组件的 MVC 中,单个前端控制器将收集、转换和验证请求参数并更新模型值本身,以便您只需要自己担心业务操作。控制器需要如何收集/转换/验证/更新值是在单个位置(视图)中定义的。由于“纯”HTML 不可能实现这一点,因此需要特定的标记语言来实现该目标。对于 JSF 2.0,它是基于 XML (XHTML) 的。您使用 XML 来定义 UI 组件,这些组件又包含有关控制器应如何收集/转换/验证/更新模型值并生成/呈现必要的 HTML 表示的信息。
此时优点和缺点应该很清楚:使用基于请求的 MVC 框架,您需要自己编写更多(样板)代码才能实现目标。然而,您最终可以对流程和 HTML/CSS/JS 输出进行更细粒度的控制。使用基于组件的 MVC 框架,您不需要自己编写太多代码。然而,您对流程和 HTML/CSS/JS 输出的细粒度控制较少。因此,如果您想要做的事情与标准描述和/或实现提供的有点不同,那么当您不这样做时,您将在基于组件的 MVC 框架中浪费更多时间。熟悉其来龙去脉。
Manfred Riem(JSF 2.x 团队成员和前 Java EE 8 MVC 1.0 规范负责人)在他的会议期间很好地概述了它关于 Devoxx 14 上的 MVC 1.0 (JSR 371) 的演讲:
另请参阅:
In request (action) based MVC, a single front controller servlet will delegate to action models based on request URL/params. You work directly with raw
HttpServletRequest
andHttpServletResponse
objects in the action model. You've to write code yourself to gather, convert and validate the request parameters and if necessary update the model values before you can ever invoke the business action.In component based MVC, a single front controller will gather, convert and validate request parameters and update the model values itself so that you only need to worry about the business action yourself. How the controller needs to gather/convert/validate/update the values is definied in a single place, the view. Since that's not possible with "plain" HTML, a specific markup language is required to achieve the goal. In case of JSF 2.0, that's XML (XHTML) based. You use XML to define UI components which in turn contain information about how the controller should gather/convert/validate/update the model values and generate/render the necessary HTML representation.
Advantages and disadvantages should be clear at this point: With a request based MVC framework you need to write more (boilerplate) code yourself to achieve the goal. However you end up with much more fine grained control over the process and the HTML/CSS/JS output. With a component based MVC framework you don't need to write much code yourself. However you have less fine grained control over the process and the HTML/CSS/JS output. So if you'd like to do things a bit differently than the standard describes and/or the implementation provides, then you'll waste a lot more time in a component based MVC framework when you're not well versed with its ins and outs.
Manfred Riem (JSF 2.x team member and ex Java EE 8 MVC 1.0 spec lead) has outlined it nicely during his speech about MVC 1.0 (JSR 371) on Devoxx 14:
See also: