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 53
Highlighting The Selected Area With Thymeleaf
Thu, Mar 23rd 2017 57
Reuse More Code With ThymeLeaf Layouts
Wed, Mar 22nd 2017 103
Introducing ThymeLeaf Fragments
Tue, Mar 21st 2017 98
Adding More Fake Data
Mon, Mar 20th 2017 209
Add The People By Location Page
Fri, Mar 17th 2017 60
Adding The People By Location Controller
Thu, Mar 16th 2017 44
Top 10
Adding More Fake Data
Mon, Mar 20th 2017 209
Reuse More Code With ThymeLeaf Layouts
Wed, Mar 22nd 2017 103
Introducing ThymeLeaf Fragments
Tue, Mar 21st 2017 98
Add The People By Location Page
Fri, Mar 17th 2017 60
Highlighting The Selected Area With Thymeleaf
Thu, Mar 23rd 2017 57
AJAX and ThymeLeaf For Modal Dialogs
Fri, Mar 24th 2017 53
Adding The People By Location Controller
Thu, Mar 16th 2017 44
Adding Locations Data To The UI
Wed, Mar 15th 2017 29
Checking Your Demo Data
Tue, Mar 14th 2017 22
Managing your source code and issue tracking
Fri, Feb 10th 2017 10


Adding Some Demo Data
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
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 that uses the repositories that we built earlier.

For this demo data I’m going to use the data repositories method as it is quick and easy and doesn’t require any sql knowledge.

Lets create a new class called DemoData that implements a Spring class called Application Runner. The class is also annotated with @Component which will allow it to be detected when the Spring Boot application starts.

Next we need access to the repositories. This is done by Autowiring them. Autowiring is a way to setup bean references in your code. Think of this as something similar to managed beans in XPages except you don’t need to edit any xml to get them working. Below is a constructor based autowire of the two repositories.

First I create two private variables in the class that will hold the beans. Next I create a constructor for the class that takes in a parameter for each bean I’m autowiring and then those to the private variables. Lastly I need to make sure I add the @Autowired annotation to the constructor. I could also have written the auto wiring as follows

but this is no longer recommended. If you see code examples like this then you can easily turn them in to constructor autowiring by allowing IntelliJ to convert them for you. Just click the code hint icon that appears when you click on the annotation and pick the constructor.

Now we just need a method that will run when the application runs. Because we extended ApplicationRunner there is a method that we can override called ‘run’ and then we can add as much data to the repositories as we like.

Here I have added one Location and one Person You can add as many as you want in your version. I do like the way that IntelliJ shows the argument names, this makes it really easy for when you next look at the code in a few months time.

One question you might ask yourself is how do we stop this ApplicationRunner from running once the application is in production as we would not want that data showing in that environment. The answer is simple and is all to do with Profiles. I’ll cover profiles in a later entry when we get around to deployments.

Now that we have data we can add it to our UI…



---------------------
http://www.qtzar.com/adding-some-demo-data/
Mar 13, 2017
8 hits



Recent Blog Posts
53
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
57
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
103
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
98
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
209
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
60
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
44
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
29
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
22
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
8
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