Tata AIG General Insurance Company - Insurer Innovation Award 2024
Blossom 2.0 Spring Integration
1. Blossom 2.0
Tobias Mattsson, Senior Software Magnolia International Ltd.
Engineer
Magnolia is a registered trademark owned by Magnolia
1 Version 1.1
International Ltd.
2. Take advantage of Spring Framework
Spring is a java based application framework
• Focus on web applications and enterprise
applications
• One of the most popular frameworks in the java
space
Pioneered a broad feature set
• Lightweight container
• Dependency Injection (DI)
• Aspect Oriented Programming (AOP)
• Enterprise Service Abstraction
Magnolia is a registered trademark owned by Magnolia
2 Version 1.1
International Ltd.
3. How Blossom integrates Spring
Integrates Spring into the module mechanism
• Module Lifecycle
Integrates with Spring Web MVC
And additional bridging
Magnolia is a registered trademark owned by Magnolia
3 Version 1.1
International Ltd.
4. Model View Controller Pattern
The controller receives input, performs requested operations and
Controller
provides the resulting model. The view is responsible for providing
the UI representation of the model.
Keeps business logic separated from presentation.
Model
View
Magnolia is a registered trademark owned by Magnolia
4 Version 1.1
International Ltd.
5. Template example
@Controller
@Template(id = "blossomSample:pages/main", title = "Main template")
public class MainTemplate {
@RequestMapping("/mainTemplate")
public String render(Node page, ModelMap model) {
return "pages/main.jsp";
}
@TabFactory("Content")
public void propertiesDialog(TabBuilder tab) {
tab.addEdit("title", "Title", "");
}
}
Magnolia is a registered trademark owned by Magnolia
5 Version 1.1
International Ltd.
6. Magnolia rendering sequence
Template Component
Component
Magnolia is a registered trademark owned by Magnolia
6 Version 1.1
International Ltd.
7. Blossom managed templates and
Template Component
C C
M M
V V
Component
C
Templates and components
are decoupled from view M
rendering V
Magnolia is a registered trademark owned by Magnolia
7 Version 1.1
International Ltd.
8. The Blossom programming model
Based on annotations
Non-intrusive
Spring centric approach
• The controller is the template
• The controller is the component
• and they’re automatically available in Magnolia
Dialogs are created programmatically
Magnolia is a registered trademark owned by Magnolia
8 Version 1.1
International Ltd.
9. Example Template with Area
@Controller
@Template(id = "blossomSample:pages/main", title = "Main template")
public class MainTemplate {
@Controller
@Area("main")
public static class MainArea {
@TabFactory("Content")
public void contentTab(TabBuilder tab) {
tab.addEdit("borderWidth", "Border width",
"Width of the border around the area");
}
@RequestMapping("/mainTemplate/main")
public String render() {
return "areas/main.jsp";
}
}
...
}
Magnolia is a registered trademark owned by Magnolia
9 Version 1.1
International Ltd.
10. Example Component
@Controller
@Template(id = "blossomSample:components/shoppingCart", title = "Shopping Cart")
@TemplateDescription("Shopping cart")
public class ShoppingCartComponent {
@RequestMapping("/shoppingCart")
public String handleRequest() {
...
return "components/shoppingCart.jsp";
}
...
}
Magnolia is a registered trademark owned by Magnolia
10 Version 1.1
International Ltd.
11. Specifying what goes into an Area
@Controller
@Area("promos")
@AvailableComponentClasses({TextComponent.class, ShoppingCartComponent.class})
public static class PromosArea {
@RequestMapping("/mainTemplate/promos")
public String render() {
return "areas/promos.jsp";
}
}
Magnolia is a registered trademark owned by Magnolia
11 Version 1.1
International Ltd.
12. Area inheritance
@Controller
@Area("promos")
@Inherits
@AvailableComponentClasses({TextComponent.class, ShoppingCartComponent.class})
public static class PromosArea {
@RequestMapping("/mainTemplate/promos")
public String render() {
return "areas/promos.jsp";
}
}
Magnolia is a registered trademark owned by Magnolia
12 Version 1.1
International Ltd.
13. Blossom Managed Dialogs
Dialogs are created using code, not configuration
Based on annotations
Detected and automatically available in Magnolia
Validation of dialog input
Magnolia is a registered trademark owned by Magnolia
13 Version 1.1
International Ltd.
14. Blossom Managed Dialogs
@DialogFactory("page-dialog")
public class PageDialog {
@TabFactory("Content")
public void contentTab(TabBuilder tab) {
tab.addEdit("title", "Title", "Title of this page");
tab.addCheckbox("navigation", "Navigation", "Include page in menu");
} Text
@TabFactory("Meta")
public void metaTab(TabBuilder tab) {
tab.addEdit("author", "Author", "");
tab.addEdit("keywords", "Keywords", "Keywords for this page");
tab.addEdit("description", "Description", "Concise page explanation");
}
}
Magnolia is a registered trademark owned by Magnolia
14 Version 1.1
International Ltd.
15. Dialog inheritance
public abstract class BaseDialog {
@TabFactory("Meta")
public void metaTab(TabBuilder tab) {
tab.addEdit("keywords", "Keywords", "Keywords for this page");
tab.addEdit("description", "Description", "Concise page explanation");
}
}
Text
@DialogFactory("news-properties")
@TabOrder("Content", “Meta”)
public class NewsPageDialog extends BaseDialog {
@TabFactory("Content")
public void contentTab(TabBuilder tab) {
tab.addEdit("subject", "Subject", "News subject");
tab.addDate("date", "Publication Date", "Date of publication");
tab.addFckEditor("text", "Text", "");
tab.addFile("image", "Image", "");
}
}
Magnolia is a registered trademark owned by Magnolia
15 Version 1.1
International Ltd.
16. Dialog validation
@DialogFactory("page-properties")
public class PagePropertiesDialog {
@TabFactory("Meta")
public void metaTab(TabBuilder tab) {
tab.addEdit("description", "Description", "A concise page explanation");
}
Text
@TabValidator("Meta")
public void validateMetaTab(DialogTab tab) {
if (tab.getSub("description").getValue().length() < 20)
AlertUtil.setMessage("Meta description needs to be longer");
}
}
Magnolia is a registered trademark owned by Magnolia
16 Version 1.1
International Ltd.
17. Templates can contain dialog factories
@Controller
@Template(id=”blossomSample:pages/section” title="Section")
public class SectionTemplate {
@RequestMapping("/section")
public ModelAndView handleRequest() {
} Text
return new ModelAndView("sectionTemplate.jsp");
@DialogFactory("section-properties")
public void propertiesDialog(DialogBuilder dialog) {
TabBuilder contentTab = dialog.addTab("Content");
contentTab.addEdit("title", "Title", "Title of this page");
TabBuilder metaTab = dialog.addTab("Meta");
metaTab.addEdit("description", "Description", "Page explanation");
}
}
Magnolia is a registered trademark owned by Magnolia
17 Version 1.1
International Ltd.
18. Dynamic dialogs
@Controller
@Template(id=”blossomSample:components/book” title=“Book”)
public class BookComponent {
@Autowired
private BookStoreWebService webService;
@RequestMapping("/book")
Text
public ModelAndView handleRequest() {
Content content = MgnlContext.getAggregationState().getCurrentContent();
String bookId = content.getNodeData("id").getString();
ModelAndView mav = new ModelAndView("book.jsp");
mav.addAttribute("book", webService.getBook(bookId));
return mav;
}
@TabFactory("Content")
public void contentTab(TabBuilder tab) {
tab.addSelect("id", "Book", "Select the book", webService.getBooks());
}
}
Magnolia is a registered trademark owned by Magnolia
18 Version 1.1
International Ltd.
19. View Technologies
Best of both worlds approach
Magnolia and Spring constructs work side by side
Built-in support for Freemarker and JSP
Everything Spring supports work out-of-the-box,
such as JSON, PDF, XML and RSS
Magnolia is a registered trademark owned by Magnolia
19 Version 1.1
International Ltd.
20. Pre-executing a controller (component)
Template Component
C C
C M M
V V
Component
C
The pre-executed controller can
choose to skip page rendering by M
sending a redirect or directly V
render something on its own
Magnolia is a registered trademark owned by Magnolia
20 Version 1.1
International Ltd.
21. Pre-executing a controller (component)
Template C Component C
C M M
<form> V V
<blossom:pecid-input />
<input type=”text” name=”email” />
... Component C
</form>
M
Outputs: V
<form>
<input type=”hidden” name=”_pecid”
value=”ff6cefa6-d958-47b1-af70-c82a414f17e1”/>
<input type=”text” name=”email” />
...
</form>
Magnolia is a registered trademark owned by Magnolia
21 Version 1.1
International Ltd.
22. Summary
Spring centric approach based on annotations
Novel features like pre-execution and dialog
validation
Code over configuration
• Versioning
• Collaboration
Enables access to Spring features and technologies
• Directly in templates, paragraphs and dialogs
Magnolia is a registered trademark owned by Magnolia
22 Version 1.1
International Ltd.
23. Resources
Documentation
• http://documentation.magnolia-cms.com/modules/
blossom.html
Wiki
• http://wiki.magnolia-cms.com/display/WIKI/Magnolia
+Blossom
Samples
• http://git.magnolia-cms.com/gitweb/?p=modules/blossom/
samples.git
Blog
• http://tobias-mattsson-magnolia.blogspot.se/
Magnolia is a registered trademark owned by Magnolia
23 Version 1.1
International Ltd.