SlideShare a Scribd company logo
Presenting ActiveWeb making Java Web programming fun...again! Igor Polevoy
About me Developer like you
Have bad aftertaste of many web frameworks
Presented ActiveJDBC to CJUG last year at about the same time
Was suggested to shut up and make a change
Currently a Chief Technologist at ProductiveEdge, Chicago
But why? Don't we have enough frameworks in Java? Restlet Brill Aranea Web Framework RSF JSF RichFaces Strecks Google Web Toolkit Aurora JPublish Jucas MyFaces WebOnSwing Chrysalis VRaptor SwingWeb Barracuda ThinWire Struts1/2 Turbine Tapestry Cocoon Spring Maverick Echo SOFIA Verge Anvil Jaffa Japple RIFE Swinglets  Millstone  Wicket  DWR  JSPWidget  JOSSO JAT  OpenXava  Stripes  Click  ZK  Caramba  wingS  Helma
All we need is: Simple to use, sophisticated on the inside
Full stack
Supporting TDD
Can test views
Dynamic
Clean URLs
Fast, lightweight (as few dependencies as possible)
Conforms to (few good) standards
Fun(because of immediate gratification)
History First version in 2009
In parallel development with ActiveJDBC
First put in production in summer 2010
Currently in production at major insurance company, 4 websites, clustered REST web services, internal tools, displacing legacy systems (Spring/Hibernate)
Meet new friend Navigate  to: http://localhost:8080/testapp/greeting?name=Bob Executes: public   class   GreetingController   extends   AppController{ public   void   index(){ view(“name”, param(“name”)); } } Renders: /WEB-INF/views/greeting/index.ftl View code: Hello, ${name}! Output: Hello, Bob! A few conventions at work here:  URL to Controller Default action view location by controller name view name by action name No configuration.  In fact, ActiveWeb has no property files, no XML, no Yaml, no text files of any kind.
Lets TDD this public   cla ss  G r eetingControllerSpec   extends   ControllerSpec{ @Test public   void   shouldRenderHelloWorld(){ request().param(“name”, “Bob”).get(“index”); a(assigns().get(“name”)).shouldBeEqual(“Bob”); } } Test HTML content: public   class  G reet ingControllerSpec   extends   ControllerSpec{ @Test public   void   shouldRenderHelloWorld(){ request().param(“name”, “Bob”). integrateViews () .get(“index”); a(responseContent().contains(“Hello,   Bob!”)).shouldBeTrue(); } } Convention at work: Controller name from spec name.
Configuration in code public   class   DbConfig   extends   AbstractDBConfig   { public   void   init(AppContext   context)   { environment( "development" ) .jndi( "jdbc/kitchensink_development" ); environment( "development" ).testing() .jdbc( "com.mysql.jdbc.Driver" ,   "jdbc:mysql://localhost/kitchensink_development"  ,   "root" ,   "****" );   environment( "hudson" ).testing() .jdbc( "com.mysql.jdbc.Driver" ,   "jdbc:mysql://172.30.64.31/kitchensink_hudson",  "root", "****" ); environment( "production" ) .jndi( "jdbc/kitchensink_production" ); } } DSL for environments, JNDI, JDBC and testing mode You get help from IDE and from compiler, less likely to make a typo
Structure of project Standard Maven structure,  View are located under:  /WEB-INF/views Controllers   are   in   app.controllers   package . Result: Huge selection of anything built under the  sun for Maven in general and Maven Web  specifically
Layouts Default Layout: src/main/webapp/WEB-INF/views/layouts/default_layout.ftl < html > < head > < LINK   href = &quot;${context_path}/css/main.css&quot;   rel = &quot;stylesheet&quot; /> < script   src = &quot;${context_path}/js/jquery-1.4.2.min.js&quot; </ script > < script   src = &quot;${context_path}/js/aw.js&quot; </ script > < title > ActiveWeb -  < @yield   to = &quot;title&quot; /></ title > </ head > < body > < div   class = &quot;main&quot; > < #include   &quot;header.ftl&quot;   > ${page_content}  < #include   &quot;footer.ftl&quot;   > </ div > </ body > </ html > Serves the same purpose as Tiles or Sitemesh, but integrated into the  system as another template. There are wrapper/nested layouts too.
<@content for and <@yield Page titles with custom tags < @content   for = &quot;title&quot; > Books List </@content> This sends content to  < @yield   to = &quot;title&quot; />  located in layout Can send any content to layout with content tag, including links to CSS, JS, etc: < @content   for = &quot;js&quot; > < script   src = &quot;${context_path}/js/page_specific.js&quot;   type = &quot;text/javascript&quot; ></ script > </ @ > Content will be rendered in layout in place of  < @yield   to = &quot;js&quot; /> This allows to easily declare content specific for a page, but rendered outside  page context.
Unobtrusive JS and <@link_to < form   id = &quot;da_form&quot;   > First name:  < input   type = &quot;text&quot;   name = &quot;first_name&quot; >< br > Last name:  < input   type = &quot;text&quot;   name = &quot;last_name&quot; >   </ form > < @link_to   controller = &quot;people&quot;   action = &quot;do-get&quot;   form = &quot;da_form&quot;   destination = &quot;result&quot; > Ajax Get </ @ > Result will be inserted into: < div   id = &quot;result&quot; ></ div > No JavaScript is generated, the HTML page is clean More ways to use Ajax with  link_to Magic happens in   aw.js
Partials Naming src/main/webapp/WEB-INF/views/greeting/_hello.ftl Rendering a partial: < @render   partial = &quot;hello&quot; /> Rendering a collection with a partial (no ugly for loops building iterative HTML): Content of  _fruit.ftl :  Fruit name: ${fruit}<hr> Host page: < @render   partial = &quot;fruit&quot;   collection = fruits /> Result of rendering: Fruit name: apple<hr>Fruit name: prune<hr>Fruit name: pear<hr> Partial will iterate itself. Also: spacers, counters, first and last.

More Related Content

PDF
ActiveJDBC - ActiveRecord implementation in Java
PPTX
Maintainable JavaScript 2012
PDF
JavaScript Library Overview
PPTX
jQuery from the very beginning
PDF
How to make Ajax work for you
PDF
Django Heresies
PDF
Design patterns revisited with PHP 5.3
PDF
jQuery Proven Performance Tips & Tricks
ActiveJDBC - ActiveRecord implementation in Java
Maintainable JavaScript 2012
JavaScript Library Overview
jQuery from the very beginning
How to make Ajax work for you
Django Heresies
Design patterns revisited with PHP 5.3
jQuery Proven Performance Tips & Tricks

What's hot (19)

PPTX
jQuery PPT
PPT
Javascript and Jquery Best practices
PPT
jQuery introduction
PDF
Create responsive websites with Django, REST and AngularJS
PPTX
SharePoint and jQuery Essentials
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PDF
Having Fun with Play
PDF
Developing Useful APIs
PDF
Html 5 in a big nutshell
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
PDF
Djangocon 2014 angular + django
PDF
Aligning Ember.js with Web Standards
PDF
Ejb3 Struts Tutorial En
PDF
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
KEY
前端概述
ZIP
Fundamental JavaScript [In Control 2009]
PPT
The Theory Of The Dom
PPT
Introduction to hibernate
jQuery PPT
Javascript and Jquery Best practices
jQuery introduction
Create responsive websites with Django, REST and AngularJS
SharePoint and jQuery Essentials
Intro To JavaScript Unit Testing - Ran Mizrahi
Having Fun with Play
Developing Useful APIs
Html 5 in a big nutshell
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Djangocon 2014 angular + django
Aligning Ember.js with Web Standards
Ejb3 Struts Tutorial En
Comparing Hot JavaScript Frameworks: AngularJS, Ember.js and React.js - Sprin...
Intro to node.js - Ran Mizrahi (28/8/14)
前端概述
Fundamental JavaScript [In Control 2009]
The Theory Of The Dom
Introduction to hibernate
Ad

Similar to ActiveWeb: Chicago Java User Group Presentation (20)

KEY
Javascript Frameworks for Well Architected, Immersive Web Apps
PPT
Grails Introduction - IJTC 2007
PDF
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
PDF
Creating Modular Test-Driven SPAs with Spring and AngularJS
PDF
Web Applications with AngularJS
PDF
PDF
Grails, Trails, and Sails: Rails Through a Coffee Filter
ODP
REST dojo Comet
PPTX
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
PPT
Grails and Dojo
PDF
MVC pattern for widgets
PPTX
Developing ASP.NET Applications Using the Model View Controller Pattern
PDF
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
PPTX
Introduction to Grails Framework
PPT
You Know WebOS
KEY
MVC on the server and on the client
PPTX
Hanselman lipton asp_connections_ams304_mvc
PDF
Orbitz and Spring Webflow Case Study
PDF
Grails @ Java User Group Silicon Valley
PDF
Introduction to Spring MVC
Javascript Frameworks for Well Architected, Immersive Web Apps
Grails Introduction - IJTC 2007
Karlsruher Entwicklertag 2013 - Webanwendungen mit AngularJS
Creating Modular Test-Driven SPAs with Spring and AngularJS
Web Applications with AngularJS
Grails, Trails, and Sails: Rails Through a Coffee Filter
REST dojo Comet
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Grails and Dojo
MVC pattern for widgets
Developing ASP.NET Applications Using the Model View Controller Pattern
MVC on the Server and on the Client: How to Integrate Spring MVC and Backbone...
Introduction to Grails Framework
You Know WebOS
MVC on the server and on the client
Hanselman lipton asp_connections_ams304_mvc
Orbitz and Spring Webflow Case Study
Grails @ Java User Group Silicon Valley
Introduction to Spring MVC
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Empathic Computing: Creating Shared Understanding
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
cuic standard and advanced reporting.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Empathic Computing: Creating Shared Understanding
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectral efficient network and resource selection model in 5G networks
SOPHOS-XG Firewall Administrator PPT.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Digital-Transformation-Roadmap-for-Companies.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
cuic standard and advanced reporting.pdf
MYSQL Presentation for SQL database connectivity
1. Introduction to Computer Programming.pptx
Big Data Technologies - Introduction.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectroscopy.pptx food analysis technology

ActiveWeb: Chicago Java User Group Presentation

  • 1. Presenting ActiveWeb making Java Web programming fun...again! Igor Polevoy
  • 3. Have bad aftertaste of many web frameworks
  • 4. Presented ActiveJDBC to CJUG last year at about the same time
  • 5. Was suggested to shut up and make a change
  • 6. Currently a Chief Technologist at ProductiveEdge, Chicago
  • 7. But why? Don't we have enough frameworks in Java? Restlet Brill Aranea Web Framework RSF JSF RichFaces Strecks Google Web Toolkit Aurora JPublish Jucas MyFaces WebOnSwing Chrysalis VRaptor SwingWeb Barracuda ThinWire Struts1/2 Turbine Tapestry Cocoon Spring Maverick Echo SOFIA Verge Anvil Jaffa Japple RIFE Swinglets Millstone Wicket DWR JSPWidget JOSSO JAT OpenXava Stripes Click ZK Caramba wingS Helma
  • 8. All we need is: Simple to use, sophisticated on the inside
  • 14. Fast, lightweight (as few dependencies as possible)
  • 15. Conforms to (few good) standards
  • 16. Fun(because of immediate gratification)
  • 18. In parallel development with ActiveJDBC
  • 19. First put in production in summer 2010
  • 20. Currently in production at major insurance company, 4 websites, clustered REST web services, internal tools, displacing legacy systems (Spring/Hibernate)
  • 21. Meet new friend Navigate to: http://localhost:8080/testapp/greeting?name=Bob Executes: public class GreetingController extends AppController{ public void index(){ view(“name”, param(“name”)); } } Renders: /WEB-INF/views/greeting/index.ftl View code: Hello, ${name}! Output: Hello, Bob! A few conventions at work here: URL to Controller Default action view location by controller name view name by action name No configuration. In fact, ActiveWeb has no property files, no XML, no Yaml, no text files of any kind.
  • 22. Lets TDD this public cla ss G r eetingControllerSpec extends ControllerSpec{ @Test public void shouldRenderHelloWorld(){ request().param(“name”, “Bob”).get(“index”); a(assigns().get(“name”)).shouldBeEqual(“Bob”); } } Test HTML content: public class G reet ingControllerSpec extends ControllerSpec{ @Test public void shouldRenderHelloWorld(){ request().param(“name”, “Bob”). integrateViews () .get(“index”); a(responseContent().contains(“Hello, Bob!”)).shouldBeTrue(); } } Convention at work: Controller name from spec name.
  • 23. Configuration in code public class DbConfig extends AbstractDBConfig { public void init(AppContext context) { environment( &quot;development&quot; ) .jndi( &quot;jdbc/kitchensink_development&quot; ); environment( &quot;development&quot; ).testing() .jdbc( &quot;com.mysql.jdbc.Driver&quot; , &quot;jdbc:mysql://localhost/kitchensink_development&quot; , &quot;root&quot; , &quot;****&quot; ); environment( &quot;hudson&quot; ).testing() .jdbc( &quot;com.mysql.jdbc.Driver&quot; , &quot;jdbc:mysql://172.30.64.31/kitchensink_hudson&quot;, &quot;root&quot;, &quot;****&quot; ); environment( &quot;production&quot; ) .jndi( &quot;jdbc/kitchensink_production&quot; ); } } DSL for environments, JNDI, JDBC and testing mode You get help from IDE and from compiler, less likely to make a typo
  • 24. Structure of project Standard Maven structure, View are located under: /WEB-INF/views Controllers are in app.controllers package . Result: Huge selection of anything built under the sun for Maven in general and Maven Web specifically
  • 25. Layouts Default Layout: src/main/webapp/WEB-INF/views/layouts/default_layout.ftl < html > < head > < LINK href = &quot;${context_path}/css/main.css&quot; rel = &quot;stylesheet&quot; /> < script src = &quot;${context_path}/js/jquery-1.4.2.min.js&quot; </ script > < script src = &quot;${context_path}/js/aw.js&quot; </ script > < title > ActiveWeb - < @yield to = &quot;title&quot; /></ title > </ head > < body > < div class = &quot;main&quot; > < #include &quot;header.ftl&quot; > ${page_content} < #include &quot;footer.ftl&quot; > </ div > </ body > </ html > Serves the same purpose as Tiles or Sitemesh, but integrated into the system as another template. There are wrapper/nested layouts too.
  • 26. <@content for and <@yield Page titles with custom tags < @content for = &quot;title&quot; > Books List </@content> This sends content to < @yield to = &quot;title&quot; /> located in layout Can send any content to layout with content tag, including links to CSS, JS, etc: < @content for = &quot;js&quot; > < script src = &quot;${context_path}/js/page_specific.js&quot; type = &quot;text/javascript&quot; ></ script > </ @ > Content will be rendered in layout in place of < @yield to = &quot;js&quot; /> This allows to easily declare content specific for a page, but rendered outside page context.
  • 27. Unobtrusive JS and <@link_to < form id = &quot;da_form&quot; > First name: < input type = &quot;text&quot; name = &quot;first_name&quot; >< br > Last name: < input type = &quot;text&quot; name = &quot;last_name&quot; > </ form > < @link_to controller = &quot;people&quot; action = &quot;do-get&quot; form = &quot;da_form&quot; destination = &quot;result&quot; > Ajax Get </ @ > Result will be inserted into: < div id = &quot;result&quot; ></ div > No JavaScript is generated, the HTML page is clean More ways to use Ajax with link_to Magic happens in aw.js
  • 28. Partials Naming src/main/webapp/WEB-INF/views/greeting/_hello.ftl Rendering a partial: < @render partial = &quot;hello&quot; /> Rendering a collection with a partial (no ugly for loops building iterative HTML): Content of _fruit.ftl : Fruit name: ${fruit}<hr> Host page: < @render partial = &quot;fruit&quot; collection = fruits /> Result of rendering: Fruit name: apple<hr>Fruit name: prune<hr>Fruit name: pear<hr> Partial will iterate itself. Also: spacers, counters, first and last.
  • 29. Lets flash public class BooksController extends AppController { @POST public void create(){ Book book = new Book(); book.fromMap(params1st()); if (book.save()){ flash( &quot;message&quot; , &quot;New book was added: &quot; + book.get( &quot;title&quot; )); redirect(BooksController. class ); } else { //handle errors } } } //Use in view: < @flash name = &quot;message&quot; /> Flash is a short-lived object, survives only one more request Use in POST/redirect for destructive operations
  • 30. Custom tags 1. Develop: public class HelloTag extends FreeMarkerTag{ protected void render(Map params, String body, Writer writer) throws Exception { writer.write(“hello”); } } 2. Register: public class FreeMarkerConfig extends AbstractFreeMarkerConfig { public void init() { registerTag(“hello”, new HelloTag()); } } 3. Use: < @hello />
  • 31. Dependency Injection with Google Guice public class HelloController extends AppController { private Greeter greeter; public void index(){ view( &quot;message&quot; , greeter.greet()); } @Inject public void setGreeter( Greeter greeter) { this .greeter = greeter; } } public class GreeterModule extends AbstractModule { protected void configure() { bind(Greeter. class ) .to(GreeterImpl. class ).asEagerSingleton(); } } public class AppBootstrap extends Bootstrap { public void init(AppContext context) { setInjector(Guice.createInjector( new GreeterModule())); } }
  • 32. TDD with DI public class GreeterMock implements Greeter{ public String greet() { return &quot;Hello from &quot; + getClass().toString(); } } public class GreeterMockModule extends AbstractModule { @Override protected void configure() { bind(Greeter. class ).to(GreeterMock. class ).asEagerSingleton(); } } public class HelloControllerSpec extends ControllerSpec { @Before public void before(){ setInjector(Guice.createInjector( new GreeterMockModule())); } @Test public void shouldTestWithMockService(){ request().get( &quot;index&quot; ); a(assigns().get( &quot;message&quot; )).shouldBeEqual( &quot;Hello from class app.services.GreeterMock&quot; ); } } Can use any mocking framework.
  • 33. Making tests web specific “ Send” parameters to controller: public class HelloControllerSpec extends ControllerSpec{ @Test public void shouldSendParamsToIndex(){ request() .param( &quot;first_name&quot; , &quot;John&quot; ).param( &quot;last_name&quot; , &quot;Deere&quot; ) .get( &quot;index&quot; ); a(assigns().get( &quot;message&quot; )) .shouldBeEqual( &quot;Hello, John Deere, welcome back!&quot; ); } } Seeing HTML in test! public class HelloControllerSpec extends ControllerSpec @Test public void shouldPrintGeneratedHTML(){ request(). integrateViews ().get( &quot;index&quot; ); System.out.println(responseContent()); // prints entire HMTL, decorated by layout. } }
  • 34. What else in tests? Transaction rolled back
  • 37. “ Send” GET, POST, DELETE, PUT HTTP requests
  • 40. Controller scenarios with IntegrationTests.
  • 41. Bootstrap entire application with AppIntegrationTests
  • 42. REST web services Controller: public class Books Controller extends AppController { public void index(){ List<Book> books = Book.findAll(); view( &quot; books&quot;, books); render().noLayout(); } } View: <? xml version = &quot;1.0&quot; encoding = &quot;UTF-8&quot; ?> < books > < #list books as book > < book > < isbn > ${book.isbn} </ isbn > < title > ${book.title} </ title > < author > ${book.author} </ author > </ book > </ #list > </ books > Access: http://host:port/context/books
  • 43. What else can controllers do? //getting parameters String name = param(“name”); List<String> selectValues = param(“myselect”); List<String> params = params1st(); Map<String, String[]> allParams = params(); //passing data to view view(“name”, name); assign(“name”, name); //detecting Ajax: if (xhr()){...} else {...} //Responding directly (short hand XML service): respond( &quot;<message>hello</message>&quot; ) .contentType( &quot;text/xml&quot; ).status( 200 ); //sending view with no layout //(useful in web services when a view is used): render().noLayout();
  • 44. Binary content in controllers //Downloading binary to client: sendFile(f).contentType( &quot;application/pdf&quot; ).status( 200 ); //Streaming large content: streamOut(in).contentType( &quot;applicaiton/pdf&quot; ); //Uploading files: Iterator<FormItem> iterator = uploadedFiles(); while (iterator.hasNext()){ FormItem item = iterator.next(); name = item.getName(); if (item.isFile()){ InputStream in = item.getInputStream()); //process data } }
  • 45. @RESTful routing @RESTful public BooksController extends AppController{} verb path action used for ------------------------------------------------------------------------------------- GET /books index display a list of all books GET /books/new_form new_form HTML form for creating a new book POST /books create create a new book GET /books/id show display a specific book GET /books/id/edit_form edit_form return an HTML form for editing a books PUT /books/id update update a specific book DELETE /books/id destroy delete a specific book
  • 46. Standard routing public BooksController extends AppController{ //GET by default public void index(){} @PUT public void save(); @DELETE public void delete(); @POST public void update(); } Allows only one HTTP method per action
  • 47. GWT Support Compile GWT client.... and PRC server on the fly: GWT server: public class EchoController extends GWTAppController implements EchoService { public String echo(String text) { return &quot;Hello from server :&quot; + text + &quot;,.... and time now is: &quot; + new Date() ; } } GWT client: business as usual GWT DEMO
  • 48. Ad hock development demo Start container
  • 55. ActiveWeb and ActiveJDBC ActiveJDBC is not baked into ActiveWeb
  • 56. ActiveJDBC is a general purpose ORM for Java
  • 57. ActiveWeb can be used with any other ORM, or without one
  • 58. ActiveWeb has nice features for managing a DB connection at runtime and during tests – tailored for ActiveJDBC, but in either case you can get access to java.sql.Connection and do with it as you wish:
  • 59. java.sql.Connection con = Base.connection();
  • 60. Conclusion Be happier with real TDD
  • 62. Have access to anything Java under the sun (there is a lot)