Web tier: servlets, JSP, Web frameworks: Java web framwork supporting MVP programming model (as ASP.NET)?

  1. Is there any java web framework that are similar to the ASP.NET programming model with a "code-behind class" (as it is called in ASP.NET) that can refer to the elements in the page by its Id, and can retrieve or inject the values (or enable/disable parts of the page) ? (can JSF be used for that, maybe in combination with something else, such as Facelets or Seam?) If so, please provide some link to an example. I think there are waaaay too many java frameworks too choose from, and do not have time to spend lots of time to learning them. Though, I have been browsing around some frameworks looking for examples, but most of them seem to be based on having java beans in a web page that pulls the values into the web page, but I rather would like a "Presenter" class (MVP pattern) to include the presentation logic, and retrieve and inject (and enable/disable content) the values into the web page. One of the consequences of the MVP pattern is that you are able to reuse the presentation logic (e.g. the code that are invoking the application/business layer and then determines whether or not some gui item should be displayed or not). http://en.wikipedia.org/wiki/Model_View_Presenter Below is an example of how the MVP pattern could be used with a Swing JFrame GUI, and how I would like the same presenter to be reused with some web framework: // an interface that can be shared between e.g. // Swing JFrame (and some web framework class ???): interface MyInterface { // ... void disableButton(); // ... more methods, including "get methods" // that can be used for retrieveing the input // from the GUI but also "set methods" for // setting input back to the GUI from // a presenter class } public class MyFrame extends JFrame implements ActionListener, MyInterface { // ... MyPresenter myPresenter; private JCheckBox jCheckBox; private JButton jButton; public MyFrame() { myPresenter = new MyPresenter(this); // this=MyInterface jButton.addActionListener(this);// this=java.awt.event.ActionListener jCheckBox = ... } public void disableButton() { // method from "MyInterface" this.jCheckBox.setEnabled(false); } // ... // Some action to be performed when some button is clicked: public void actionPerformed(ActionEvent e) { // method from ActionListener this.myPresenter.actionMethod(); } // ... } public class MyCodeBehindClass extends SomeWebFrameworkClass implements MyInterface { // ... MyPresenter myPresenter; public SomeWebFrameworkClass() { myPresenter = new MyPresenter(this); } public void disableButton() { // method from "MyInterface" this.getWebPageTemplate("mypage.html").getItemId("myButton").setEnabled(false); // note that the above kind of code would be better if it also could be // strongly typed in some Java IDE, as in ASP.NET with Visual Studio.NET // where you could have a direkt reference to all items in the webpage // with intellisense like this: // this.myButton.setEnabled(false); // (when pressing the "." after writing "this.mybutton." above // you should get a dropdown with the available methods for the checkbox) } // Some action to be performed when something is clicked: public void someEventMethodTriggeredBySomeWebFramework(SomeEventParameter e) { this.myPresenter.actionMethod(); } // ... } some of the content of the above refered "mypage.html" .... ... .... public class MyPresenter { MyInterface myInterface; public (MyInterface myInterface) { this.myInterface = myInterface; } public actionMethod() { int i = this.myInterface.getSomething1(); String s = this.myInterface.getSomething2(); // ... SomeDomainObject someDomainObject = ... // presentation logic that can be reused for different GUI's: if(someDomainObject.isSomePropertySet()) { this.myInterface.disableButton(); } // set more stuff to the GUI through with more // methods of the view interface that // can be shared between e.g. Swing GUI // or a web framework GUI ... } } / Tom
  2. You can take a look at Wicket, http://wicket.apache.org/ /Tomas
  3. If you think Swing can be used for MVP pattern then you can develop Swing UI and deploy with AjaxSwing to the web. http://ajaxswing.com/