MVC 和 Java-EE
这些年来,我对模型-视图-控制器设计模式及其提供的好处越来越感兴趣。但当涉及到 Web 应用程序时,我正在努力充分利用这些优势。
如果我要创建一个名为 UsersComponent 的组件,其中包含:
- 用户列表
- 主动过滤此用户列表的文本字段
那么在 Java Swing 中,您可以轻松地创建一个扩展 JPanel 的 UserComponent 类,并在 UserComponent 内部,您可以吗?模型、视图和控制类。您最终将得到一个非常容易重复使用的组件。
现在,我想做的是在 Java-EE 中模仿这一点。字符串模板似乎为此提供了一个解决方案。但是,还有一个额外的变化。我喜欢网页设计师。我很乐意为他们提供添加组件的机会,而无需开发人员参与或花太多精力考虑他们应该使用什么入口点。
例如,假设我们有一个基本页面模板,设计者希望在此页面上的某个位置添加 UserComponent 组件。然后,您需要填充模型,在大多数情况下基于某些请求参数。
所以,这是真正的问题。有谁知道确定给定模板中包含哪些模板的方法。因此,您可以在运行时(或者更确切地说每次修改时)分析此模板,并在主页控制器中进行适当的内务处理?
基本上,我可以完成此任务:
- 设计器创建一个字符串模板。比如说,MyPage.st
- Rewrite 模块将 www.mydomain.com/IgnoredFolderNameForSeo/MyPage 更改为 www.mydomain.com/pagerenderservlet?templateName=MyPage
- 页面呈现 Servlet 根据参数加载字符串模板,对其进行分析以确定在其中使用哪些组件字符串模板并根据需要初始化它们。
目前,我能想到的最佳解决方案是为不同的基页提供不同的 servlet,从而公开不同的功能子集。但我对这个解决方案一点也不满意。如果可以动态处理它,那就整洁多了。基本上,拥有所有受支持组件的处理程序,但仅初始化/处理实际需要的组件。
我很想听听你们对此的想法:)
**更新**
我认为我提到的摇摆让这件事有点混乱。我想做的是通过字符串模板创建供网络设计者使用的组件,然后他们可以将其包含在任何给定的字符串模板中。
所以我想这一切都归结为这一点。
有谁知道字符串模板框架,它可以让我在运行时确定字符串模板中包含哪些其他字符串模板。
During the years, I grown quite the affection for the Model-View-Controller design pattern and the benefits it provides. But I'm struggling to make full use of these benefits when it comes to web applications.
If I was to create a component called UsersComponent, which consists of:
- a list of users
- a text field which actively filters this list of users
Then in Java Swing, You could easily do a class UserComponent which extended JPanel, and inside UserComponent, have you model, view and control classes. And you'll end up with a very easily re-uable component.
Now, what I would love to do, is to mimic this in Java-EE. String templates seems to provide a solution for this. BUT, with a added twist. I like web designers. And I would love to provide them with a opportunity of adding components without having to involve a developer or putting to much though into what entry point they should use.
For example, lets say we have a base page template, and the designer wishes to add the UserComponent component somewhere on this page. You will then need to populate the model, in most cases based on some request parameters.
So, here's the actual question. Does anybody know of a way, of determining which templates are included in a given template. So you could analyse this template at runtime (or rather every time its modified), and do the appropriate housekeeping in the main page controller?
Basically, so I could accomplish this:
- Designer creates a stringtemplate. Say, MyPage.st
- Rewrite module changes www.mydomain.com/IgnoredFolderNameForSeo/MyPage into www.mydomain.com/pagerenderservlet?templateName=MyPage
- the page rendering servlet loads the stringtemplate based on the parameter, analyses it to determining which components are used within the string template and initializes them as needed.
Currently, the best solution I have been able to come up with is to have different servlets for different base pages, which exposes different subsets of functionality. But I'm not at all happy with this solution. It would be so much neater, if there was a possibility of handling it dynamically. Basically, having handlers for ALL supported components but only initializing/handling the ones which are actually needed.
I would love to hear your guys thoughts on this :)
** UPDATE **
I think my mentions of swing have confused this matter a little bit. What I would love to do is to create components, available to web designers though string templates, which they can then include in any given string template.
So i suppose it all comes down to this.
Does any body know a string template framework, which lets me determine at run time, which other string templates are included in a string template.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定是否理解您的问题:您是否已经尝试过 Struts 2、Spring MVC 或 JSF 等框架?
这些框架中是否缺少一些东西?
I'm not sure to understand your question : have you already tried frameworks like Struts 2, Spring MVC, or JSF ?
Is there something missing for you in those frameworks ?
如果您想使用 MVC(或 MVP)进行类似 Swing 的 Web 开发,您应该尝试 GWT
If you want to do web Swing-like developpement with MVC (or MVP), you should try GWT