简体   繁体   English

MVC 和 Java-EE

[英]MVC and Java-EE

During the years, I grown quite the affection for the Model-View-Controller design pattern and the benefits it provides.这些年来,我越来越喜欢 Model-View-Controller 设计模式及其提供的好处。 But I'm struggling to make full use of these benefits when it comes to web applications.但是当涉及到 web 应用程序时,我正在努力充分利用这些优势。

If I was to create a component called UsersComponent, which consists of:如果我要创建一个名为 UsersComponent 的组件,它包括:

  • 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. 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.现在,我想做的是在 Java-EE 中模仿这一点。 String templates seems to provide a solution for this.字符串模板似乎为此提供了解决方案。 BUT, with a added twist.但是,有一个额外的转折。 I like web designers.我喜欢 web 设计师。 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.例如,假设我们有一个基本页面模板,并且设计者希望在此页面的某处添加 UserComponent 组件。 You will then need to populate the model, in most cases based on some request parameters.然后,您将需要填充 model,在大多数情况下,基于一些请求参数。

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?因此,您可以在运行时(或者更确切地说,每次修改时)分析此模板,并在主页 controller 中进行适当的内务管理?

Basically, so I could accomplish this:基本上,所以我可以做到这一点:

  • Designer creates a stringtemplate.设计器创建一个字符串模板。 Say, MyPage.st说,MyPage.st
  • Rewrite module changes www.mydomain.com/IgnoredFolderNameForSeo/MyPage into www.mydomain.com/pagerenderservlet?templateName=MyPage重写模块将 www.mydomain.com/IgnoredFolderNameForSeo/MyPage 更改为 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.页面渲染 servlet 根据参数加载字符串模板,分析它以确定字符串模板中使用了哪些组件,并根据需要对其进行初始化。

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.目前,我能想出的最佳解决方案是为不同的基本页面设置不同的 servlets,从而公开不同的功能子集。 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.我认为我提到的 swing 有点混淆了这个问题。 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.我想做的是创建组件,web设计人员可以通过字符串模板使用,然后他们可以将其包含在任何给定的字符串模板中。

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.有没有人知道字符串模板框架,它让我在运行时确定字符串模板中包含哪些其他字符串模板。

I'm not sure to understand your question: have you already tried frameworks like Struts 2, Spring MVC, or JSF?我不确定是否理解您的问题:您是否已经尝试过诸如 Struts 2、Spring MVC 或 JSF 之类的框架?

Is there something missing for you in those frameworks?在这些框架中,您是否缺少某些东西?

If you want to do web Swing-like developpement with MVC (or MVP), you should try GWT如果你想用 MVC(或 MVP)做 web Swing-like developmentpement,你应该试试GWT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM