193 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
AJAX and ThymeLeaf For Modal Dialogs
Fri, Mar 24th 2017 70
Highlighting The Selected Area With Thymeleaf
Thu, Mar 23rd 2017 62
Reuse More Code With ThymeLeaf Layouts
Wed, Mar 22nd 2017 109
Introducing ThymeLeaf Fragments
Tue, Mar 21st 2017 107
Adding More Fake Data
Mon, Mar 20th 2017 163
Add The People By Location Page
Fri, Mar 17th 2017 43
Adding The People By Location Controller
Thu, Mar 16th 2017 35
Top 10
Adding More Fake Data
Mon, Mar 20th 2017 163
Reuse More Code With ThymeLeaf Layouts
Wed, Mar 22nd 2017 109
Introducing ThymeLeaf Fragments
Tue, Mar 21st 2017 107
AJAX and ThymeLeaf For Modal Dialogs
Fri, Mar 24th 2017 70
Highlighting The Selected Area With Thymeleaf
Thu, Mar 23rd 2017 62
Add The People By Location Page
Fri, Mar 17th 2017 43
Adding The People By Location Controller
Thu, Mar 16th 2017 35
Adding Locations Data To The UI
Wed, Mar 15th 2017 28
Checking Your Demo Data
Tue, Mar 14th 2017 21
Deciding on a frontend
Fri, Feb 3rd 2017 9


Controlling The Frontend
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Declan Lynch    

Before we can start building our frontend we need to tell our Spring Boot application how to handle the incoming requests and what html page to display. This is done using Spring MVC which we added when we picked the spring-boot-starter-web dependency in the Spring Initializer. This dependency adds a built in tomcat web server that is configured with a set of defaults and sets up the application to scan for special classes that have been annotated with @Controller

When a class is annotated with @Controller Spring MVC knows that it will contain methods that have been annotated in such a way that the method can be mapped to a specific request.

I’ve created a new package in my source to hold all my controllers called, you guessed it, controllers. In here I have created a new java class called HomeController and I have annotated it the @Controller annotation above the class name. I then added a single method to the class and I have annotated that with @RequestMapping(“/”) which means whenever a request comes in that matches the root of the site you should return the string ‘home’.

This returned string is intercepted by Spring MVC and is passed to the configured template renderer which in our case is Thymeleaf. Thymeleaf will then look in the resources/templates folder for a html file called home.html and will send that to the web browser.

If we were to run the application right now we would get an error as we don’t have that html file yet.

The other thing to notice is that the RequestMapping method accepts a ModelMap called model. This is where we can add data to the model so that when the Thymeleaf processor is rendering the page it can take the data from the model and slot it in to place, This is very like how an XPage application can put values in to the rendered html. Right now I’m not putting anything in to the model so I’ll come back to that later.



---------------------
http://www.qtzar.com/controlling-the-frontend/
Mar 08, 2017
5 hits



Recent Blog Posts
70
AJAX and ThymeLeaf For Modal Dialogs
Fri, Mar 24th 2017 8:30p   Declan Lynch
The final part of the basic phonebook application is being able to click on a person and see details about them. For this part I’ve decided for now not to open a new page but to open the persons details in a modal dialog box on the current screen just so I can demo how to do ajax calls using Spring and Thymeleaf. First of all I need a PersonController which will populate the modelmap with the selected persons attributes and then return a thymeleaf page. This controller is very simple an
62
Highlighting The Selected Area With Thymeleaf
Thu, Mar 23rd 2017 4:30p   Declan Lynch
Now that I have pulled the side navigation menu out in to its own reusable code fragment I can now make a small adjustment to it to highlight the currently selected option in the navigator. In the Domino/XPage world this would be the script that you write to add a css class to a menu item using the selected property. For the bootstrap based side navigator that I am using in this application you can add a background color to the side navigator by adding a css class of ‘active’ to the
109
Reuse More Code With ThymeLeaf Layouts
Wed, Mar 22nd 2017 12:30p   Declan Lynch
As you saw in the last entry you can use ThymeLeaf Fragments to split out reusable parts of your html pages so that you can just drop them in where needed just like Custom Controls in XPages. Another great XPage concept was using a Custom Control to design the main layout of your page and then drop the content for the page that you are displaying in to a facet on that custom control. With an add-on to ThymeLeaf, which is automatically supplied when using ThymeLeaf with SpringBoot, this is also e
107
Introducing ThymeLeaf Fragments
Tue, Mar 21st 2017 12:30p   Declan Lynch
When I created my people by location page I just copied the entire home page of the application. I now want to make a few changes to the side navigator but if I leave things as they are now I would have to make those changes in all pages that share the side navigator. In the XPages world we had custom controls which could be used to break your page in to separate components and ThymeLeaf has a similar concept called Fragments. Under my templates folder I’m going to create a new folder cal
163
Adding More Fake Data
Mon, Mar 20th 2017 12:30p   Declan Lynch
In the last entry we added our new People By Location page and when we looked at in the the browser is was fairly empty apart from the one test user. Not very easy to do any proper testing with just one entry. You COULD if you wanted add a bunch more test users manually but what if you wanted to test with a few thousand users, that would be a lot of copy/pasting. Thankfully there is an easier way using a Data Faker. First I need to add a new dependency to my pom file for the JavaFaker project o
43
Add The People By Location Page
Fri, Mar 17th 2017 12:30p   Declan Lynch
Now that the controller is created and has been committed to our source control it is time to create the page that is associated with it. I’ve started by copying the home.html page to it’s own file called location.html (to match the string returned by the controller in the last entry). I’ll break this in to components in a later part but for now a quick copy is all I need to get the exact same layout as the home page. For the list of peoples details I’ve decided to use Da
35
Adding The People By Location Controller
Thu, Mar 16th 2017 12:30p   Declan Lynch
Now that we have the main landing page of the application created it is time to build our next page. To start the process of I have gone to VSTS and dragged the ‘See All Staff In A Single Location’ story over to the Active column. I can now return to IntelliJ and start building my next controller. I’m going to add a new controller class to the application called LocationController. Don;t forget to annotate the called with the @Controller annotation so that Spring MVC will pick
28
Adding Locations Data To The UI
Wed, Mar 15th 2017 12:30p   Declan Lynch
Now that we have our demo data and we have confirmed that it exists when we start the application it is time to add it to the Thymeleaf based UI. First we need to add it to the data model that is used when the page is rendered. If we return to our HomeController class we need to make a couple of changes. First we need to get access to the LocationRepository bean. We do this by adding an Autowired reference the bean using the same method that we did when building the demo data. Then we need to ad
21
Checking Your Demo Data
Tue, Mar 14th 2017 6:30p   Declan Lynch
Now that we have the demo data how do we know that it is actually working and getting in to the database. It would be rather pointless trying to add the data to the UI if there is no data to add. If you are using a persistent datasource then you can just use whatever databases tools you normally use to check the tables, but in our case we are using an in-memory database that disappears when the application is exited. Thankfully, however, the H2 in-memory database does have an admin console and S
7
Adding Some Demo Data
Mon, Mar 13th 2017 12:30p   Declan Lynch
Before we can start displaying data in our application we need to add some demo data. You could point the data source to be an external persistent data source that contains test data instead of using an in-memory data source that is lost each time to stop the application or you could load up the in-memory data source with demo data each time the application is started by using either a sql file containing statements to add the data or by writing a script that runs when the application starts th




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition