Top Banner
Chicago, October 19 - 22, 2010 Next Generation Spring MVC with Spring Roo Stefan Schmidt & Keith Donald
32

Next Generation Spring MVC with Spring Roo

May 25, 2015

Download

Technology

Stefan Schmidt

Next Generation Spring MVC with Spring Roo
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Next Generation Spring MVC with Spring Roo

Chicago, October 19 - 22, 2010

Next Generation Spring MVC with Spring Roo Stefan Schmidt & Keith Donald

Page 2: Next Generation Spring MVC with Spring Roo

Agenda

•  Mastering Spring MVC with Spring Roo •  Keeping up with project domain changes •  View scaffolding & customization •  How social is your application? •  Does your application speak Spanish? •  How secure is your application? •  Going with the flow

Page 3: Next Generation Spring MVC with Spring Roo

Mastering Spring MVC with Spring ROO

Page 4: Next Generation Spring MVC with Spring Roo

Master Spring MVC with Spring Roo

•  Best-practice Spring MVC out of the box –  REST support –  Round tripping of View artifacts –  Strong Templating support –  Theming support –  Pagination support –  i18n & i11n built-in –  Form validation based on JSR 303 –  Tested on popular Web browsers & Web containers

Page 5: Next Generation Spring MVC with Spring Roo

REST Support - Form Handling

Resource GET PUT POST DELETE Collection URI such as http://tld.com/pizzashop/toppings

List members of the collection (pagination possible)

Not used. Create new resource

Not used.

Member URI such as http://tld.com/pizzashop/toppings/5

Retrieve addressed resource

Update the addressed resource

Not used. Delete the addressed resource

Member URI such as http://tld.com/pizzashop/toppings?form

Creates a initialized but empty form for the resource (create use-case)

Not used. Not used. Not used.

Member URI such as http://tld.com/pizzashop/toppings/5?form

Creates an initialized form pre-populated with data of resource (update use-case)

Not used. Not used. Not used.

Page 6: Next Generation Spring MVC with Spring Roo

REST Support - Customizable JSON Binding

•  Roo offers two methods for integrating JSON binding: –  Option 1: Spring MVC detects Jackson

•  @RequestBody & @ResponseBody •  ContentNegotiatingViewResolver

–  Option 2: Built-in JSON handling managed in domain layer •  Customizable FlexJson integration

Page 7: Next Generation Spring MVC with Spring Roo

Spring Roo MVC Scaffolding Options

•  Generation of Web artifacts –  controller scaffold

•  generate a controller for a given entity –  controller all

•  generate controllers for all entities without an existing controller

–  controller class •  generate a simple Spring @MVC controller with a post and a

get method

Page 8: Next Generation Spring MVC with Spring Roo

DEMO View scaffolding

Page 9: Next Generation Spring MVC with Spring Roo

Keeping up with project domain changes

Page 10: Next Generation Spring MVC with Spring Roo

Keeping up with project domain changes

Past: Roo 1.0.x all-or-nothing approach –  either manage view templates manually after initial scaffold, –  or abstain from customization of JSP view artifacts

Future: Roo 1.1.x intelligent round-tripping –  introduction of customizable tag library –  reduction of JSP code by ~90% –  JSPs are now user editable

Page 11: Next Generation Spring MVC with Spring Roo

JSP View Round-Tripping

•  Customizable Tag libraries –  every tag has three common attributes

•  ‘id’ is used by Roo to identify tags via Xpath (required) •  ‘z’ is used to store a hash code which determines who ‘owns’

the tag (required) •  ‘render’ can be used to omit form rendering of the tag

Page 12: Next Generation Spring MVC with Spring Roo

JSP View Round Tripping Cont.

Example jspx file:

<form:update  id="fu_com_foo_Person"  modelAttribute="person"  path="/people"                                  z="3lX+WZW4CQVBb7OlvB0AvdgbGRQ=">  

   <field:datetime  dateTimePattern="${person_birthday_date_format}"  field="birthDay"                                            id="c_com_foo_Person_birthDay"  z="dXnEoWaz4rI4CKD9mlz+clbSUP4="/>  

   <field:select  field="car"  id="c_com_foo_Person_car"  itemValue="id"  items="${cars}"                                            path="/cars"  z="z2LA3LvNKRO9OISmZurGjEczHkc="/>  

   <field:select  field="cars"  id="c_com_foo_Person_cars"  itemValue="id"  items="${cars}"                                            multiple="true"  path="/cars"  z="c0rdAISxzHsNvJPFfAmEEGz2LU4="/>  </form:update>  

Page 13: Next Generation Spring MVC with Spring Roo

Hash Key Calculation

Things included in hash code calulation

Things not included in hash key calculation

Element name (name only, not namespace)

Name space of element names

Attribute names present in element White spaces used in the element

Attribute values present in the element Potential child elements

The ‘z’ attribute and its value

Any attribute (and value) whose name starts with '_'

The order of the attributes does not contribute to the value of a hash key

Page 14: Next Generation Spring MVC with Spring Roo

DEMO View round-tripping

Page 15: Next Generation Spring MVC with Spring Roo

View Scaffolding & Customization

Page 16: Next Generation Spring MVC with Spring Roo

View Scaffolding & Customization

•  Roo MVC views offer numerous customization points: –  Spring Theming support via CSS (and graphics) –  Global template structural adjustments via Tiles –  Page structure changes in JSP pages –  Portable templates through JSP tag library – 

Page 17: Next Generation Spring MVC with Spring Roo

Roo Default Tag Library

•  Spring JavaScript •  Dojo Toolkit •  Easy XML-based tags (no .java required) •  Tags for

–  form handling –  field rendering –  util (pagination, page decoration, language selection, …)

Page 18: Next Generation Spring MVC with Spring Roo

DEMO View customization

Page 19: Next Generation Spring MVC with Spring Roo

How social is your application?

Page 20: Next Generation Spring MVC with Spring Roo

Embedding Social Features

Page 21: Next Generation Spring MVC with Spring Roo

Embedding Social Features

Roo offers two shell commands to install features: •  Option 1

–  web mvc embed generic --url http://www.youtube.com/watch?v=Gb1Z0lfl52I –  automatic detection of social feature based on domain name –  easiest way to get a feature embedded

•  Option 2 –  web mvc embed map --provider GOOGLE_MAPS --location "Sydney,

Australia” –  web mvc embed finances --stockSymbol VMW –  specification of type of social feature –  better supported through tab completion

Page 22: Next Generation Spring MVC with Spring Roo

DEMO Embedding Social Features

Page 23: Next Generation Spring MVC with Spring Roo

Does your app speak Spanish?

Page 24: Next Generation Spring MVC with Spring Roo

i18n & l11n Support

•  Roo MVC scaffolding now defaults to locale ‘en’ –  install more languages with ‘web mvc install --language es’

command –  choice between 6 languages

–  very easy publishing of new languages •  addon create i18n --topLevelPackage com.foo.ru --locale ru --messageBundle

<path-to>/messages_fr.properties •  see slides for session ‘Hello, RooBot: Writing and Distributing Your Own

Spring Roo Add-Ons’

Page 25: Next Generation Spring MVC with Spring Roo

i18n & l11n Support

•  Roo MVC scaffolding uses two artifacts for managing localization (l11n) & internationalization (i18n) –  application.properties

•  application / domain specific messages •  managed by Roo round tripping

–  messages_XX.properties •  non- application / domain specific messages •  never touched by Roo after initial install

Page 26: Next Generation Spring MVC with Spring Roo

How secure is your application?

Page 27: Next Generation Spring MVC with Spring Roo

Integrating Spring Security

•  One simple command –  security setup –  URL-based security with applicationContext-security.xml

<http  auto-­‐config="true"  use-­‐expressions="true">      <form-­‐login  login-­‐processing-­‐url="/resources/j_spring_security_check"  login-­‐                                    page="/login"  authentication-­‐failure-­‐url="/login?login_error=t"/>      <logout  logout-­‐url="/resources/j_spring_security_logout"/>  

   <intercept-­‐url  pattern="/choices/**"  access="hasRole('ROLE_ADMIN')”/>        <intercept-­‐url  pattern="/resources/**"  access="permitAll"  />      <intercept-­‐url  pattern="/**"  access="permitAll"  />  </http>  

Page 28: Next Generation Spring MVC with Spring Roo

Going with the Flow

Page 29: Next Generation Spring MVC with Spring Roo

Spring Web Flow

•  One simple command –  web flow –  integrates Spring Web Flow into application

Page 30: Next Generation Spring MVC with Spring Roo

DEMO

Securing Your Application Spring Web Flow Selenium Tests

Page 31: Next Generation Spring MVC with Spring Roo

Resources & Links

•  Home → http://www.springsource.org/roo –  Contains links to all other resources

•  Forum → http://forum.springsource.org –  Roo team actively monitor forum and answer queries

•  Issues → http://jira.springframework.org/browse/ROO

•  Twitter → @SpringRoo –  Follow for updates, or include in tweets so we see them

•  Contact details –  Keith Donald @kdonald, [email protected] –  Stefan Schmidt @schmidtstefan, [email protected]

Page 32: Next Generation Spring MVC with Spring Roo

Q&A