Summary Build a semi-standard system using the Thymeleaf template engine! MASSIVE firepower here, and you NEED...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Summary Build a semi-standard system using the Thymeleaf template engine! MASSIVE firepower here, and you NEED to make this run! If you've fallen behind in the exercises, there is literally no other time than now to catch up. Do it today (literally today!) or risk repeating the course! Seriously! If you're not completely caught up with the class by the midnight tomorrow or so, you're risking flat out failure. I suspect you can see this material is cumulative, and also that this course moves fast! Enough lecture though. My guess is that at least 90% of you are exactly caught up and target. Give yourselves a pat on the back if you're ready to begin this exercise right now! Step 1 Create a new project called ex32_thymeleaf which uses Spring DevTools, Spring Web, Thymeleaf, and Lombok repos. Inside, create a new POJO in a ca.sheridancollege.<yourUserName>.beans package called Course. In Course, create a private String prefix, a private String code, and a private String name. Always a good idea to create a private Long id too - they come in handy sometimes! Lombok your Course POJO with @Data, @NoArgsConstructor, @AllArgsConstructor, and @Builder. Step 2 Now create a Course Controller class in a ca.sheridancollege.<yourUserName>.controllers package. Annotate your class with @Controller! A simple, but easily forgettable step! Inside Course Controller, use the following line of code at the top to store a List of Course instances. It uses a bit of Polymorphism to stuff a CopyOnWriteArrayList into a List Interface shaped hole, as we've discussed previously. No need to do any injection here today like last time though, unless you really want to and are confident you previously. No need to do any injection here today like last time though, unless you really want to and are confident you can make it work with some modifications to the code below! For today, simple and easy so we can focus on the Thymeleaf instead. List<Course> courseList = new CopyOnWriteArrayList<Course>(); Write a GET mapped method for requests to "/" called index. Make sure your method grabs a Model model instance as a parameter too! We'll need it in a sec.. your method should return to "index". Just BEFORE your return to "index" though, add your course List instance to your model as well. model.addAttribute("courseList", courseList); // friendly note, the quotes here won't copy!!! Step 3 Now create an HTML file called index.html in your resources / templates directory. This will have two parts: a table to display our courses so far, and a form where we can easily add a new one! Don't forget, we must add our Thymeleaf XML namespace to this page to have it function with Thymeleaf templating technology! Change your <html> tag to the following: <html xmlns:th="https://www.thymeleaf.org"> Don't forget, we must add our Thymeleaf XML namespace to this page to have it function with Thymeleaf templating technology! Change your <html> tag to the following: <htm1 xmlns:th="https://www.thymeleaf.org"> To display the courses, we need a <table> with table headings (<th>Heading!</th>) for each field, ideally. This part is easy - Google for the HTML table example tutorial page from W3Schools if you've forgotten any of this stuff. The W3 folks are responsible for standardizing HTML proper anyway, so they're a great resource on simple tags and attributes! Also inside the table, but as a second row (or third or whatever - depends on what we want to display!), add the following code: <tr th:each="aCourse:${courseList}"> <td th: text="${aCourse.id}">55</td> <td th: text="${aCourse.prefix}">PROG</td> Repeat for code and name, then close the row tag and table with closing tags. Step 4 Now, underneath your table, create a form. Our form should use the POST method. It needs an action, but for styling purposes, our regular action will just go to "#", otherwise known as nowhere because our server isn't there to process it yet. Meanwhile, if we're using Thymeleaf with Spring Boot, on the other hand, a th:action attribute going to @{/addCourse} should do the trick! <form method="post" action="#" th: action="@{/addCourse}"> </form> Be mindful of the symbols in front of Thymeleaf variables! Remember, use $ for most model attributes, and use @ for locations! Inside the form tags, we need regular fields for our Course POJO params. Here are a few you can copy if you wish: ID: <input type="number" name="id" /><br> Prefix: <input type="text" name="prefix" /><br> Code: <input type="number" name="code" /><br> Name: <input type="text" name="name" /><br> <input type="submit" value="Add Course!" /> Step 5 This last part is easy now.. Back at the Controller, create a method to handle POST requests to "/addCourse", and retrieve your @Request Params per the form. We've done this a few times already! Create a new Course instance out of your request params, and add it to your list as follows: Course course = new Course (id, prefix, code, name); courseList.add (course); Finally, add your updated list to your model for display by Thymeleaf again, and then return to "index" as before! model.addAttribute("courseList", courseList); If you have time, make it look pretty! Believe me when I say this is code we'll use again and again, and having an easy pattern to follow in the future is sometimes super helpful! For your exercise submission, add at least three unique courses using our system, then take a screenshot of them displayed using Spring Boot and Thymeleaf with a bit of style! As always, use your name as the filename(s). Awesome! Powerful stuff!! Summary Build a semi-standard system using the Thymeleaf template engine! MASSIVE firepower here, and you NEED to make this run! If you've fallen behind in the exercises, there is literally no other time than now to catch up. Do it today (literally today!) or risk repeating the course! Seriously! If you're not completely caught up with the class by the midnight tomorrow or so, you're risking flat out failure. I suspect you can see this material is cumulative, and also that this course moves fast! Enough lecture though. My guess is that at least 90% of you are exactly caught up and target. Give yourselves a pat on the back if you're ready to begin this exercise right now! Step 1 Create a new project called ex32_thymeleaf which uses Spring DevTools, Spring Web, Thymeleaf, and Lombok repos. Inside, create a new POJO in a ca.sheridancollege.<yourUserName>.beans package called Course. In Course, create a private String prefix, a private String code, and a private String name. Always a good idea to create a private Long id too - they come in handy sometimes! Lombok your Course POJO with @Data, @NoArgsConstructor, @AllArgsConstructor, and @Builder. Step 2 Now create a Course Controller class in a ca.sheridancollege.<yourUserName>.controllers package. Annotate your class with @Controller! A simple, but easily forgettable step! Inside Course Controller, use the following line of code at the top to store a List of Course instances. It uses a bit of Polymorphism to stuff a CopyOnWriteArrayList into a List Interface shaped hole, as we've discussed previously. No need to do any injection here today like last time though, unless you really want to and are confident you previously. No need to do any injection here today like last time though, unless you really want to and are confident you can make it work with some modifications to the code below! For today, simple and easy so we can focus on the Thymeleaf instead. List<Course> courseList = new CopyOnWriteArrayList<Course>(); Write a GET mapped method for requests to "/" called index. Make sure your method grabs a Model model instance as a parameter too! We'll need it in a sec.. your method should return to "index". Just BEFORE your return to "index" though, add your course List instance to your model as well. model.addAttribute("courseList", courseList); // friendly note, the quotes here won't copy!!! Step 3 Now create an HTML file called index.html in your resources / templates directory. This will have two parts: a table to display our courses so far, and a form where we can easily add a new one! Don't forget, we must add our Thymeleaf XML namespace to this page to have it function with Thymeleaf templating technology! Change your <html> tag to the following: <html xmlns:th="https://www.thymeleaf.org"> Don't forget, we must add our Thymeleaf XML namespace to this page to have it function with Thymeleaf templating technology! Change your <html> tag to the following: <htm1 xmlns:th="https://www.thymeleaf.org"> To display the courses, we need a <table> with table headings (<th>Heading!</th>) for each field, ideally. This part is easy - Google for the HTML table example tutorial page from W3Schools if you've forgotten any of this stuff. The W3 folks are responsible for standardizing HTML proper anyway, so they're a great resource on simple tags and attributes! Also inside the table, but as a second row (or third or whatever - depends on what we want to display!), add the following code: <tr th:each="aCourse:${courseList}"> <td th: text="${aCourse.id}">55</td> <td th: text="${aCourse.prefix}">PROG</td> Repeat for code and name, then close the row tag and table with closing tags. Step 4 Now, underneath your table, create a form. Our form should use the POST method. It needs an action, but for styling purposes, our regular action will just go to "#", otherwise known as nowhere because our server isn't there to process it yet. Meanwhile, if we're using Thymeleaf with Spring Boot, on the other hand, a th:action attribute going to @{/addCourse} should do the trick! <form method="post" action="#" th: action="@{/addCourse}"> </form> Be mindful of the symbols in front of Thymeleaf variables! Remember, use $ for most model attributes, and use @ for locations! Inside the form tags, we need regular fields for our Course POJO params. Here are a few you can copy if you wish: ID: <input type="number" name="id" /><br> Prefix: <input type="text" name="prefix" /><br> Code: <input type="number" name="code" /><br> Name: <input type="text" name="name" /><br> <input type="submit" value="Add Course!" /> Step 5 This last part is easy now.. Back at the Controller, create a method to handle POST requests to "/addCourse", and retrieve your @Request Params per the form. We've done this a few times already! Create a new Course instance out of your request params, and add it to your list as follows: Course course = new Course (id, prefix, code, name); courseList.add (course); Finally, add your updated list to your model for display by Thymeleaf again, and then return to "index" as before! model.addAttribute("courseList", courseList); If you have time, make it look pretty! Believe me when I say this is code we'll use again and again, and having an easy pattern to follow in the future is sometimes super helpful! For your exercise submission, add at least three unique courses using our system, then take a screenshot of them displayed using Spring Boot and Thymeleaf with a bit of style! As always, use your name as the filename(s). Awesome! Powerful stuff!!
Expert Answer:
Answer rating: 100% (QA)
The code you provided is for a Java Swing application that creates a simple calculator The user can ... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
1. Find and correct the error(s) in each of the following segments of codes and explain how to correct it. a) public static int sum (int x, int y) // not allowed to change { int result; result=x+y;...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
Suppose a country's productivity last year was 84. If this country's productivity growth rate of 5 percent is to be maintained, this means that this year's productivity will have to be: A. 88.2. B....
-
a) What capacity-related design considerations and demand modifications are most important to a city that is planning to build a sports arena? b) For the following 2 organizations: telephone company...
-
Assume that the processes in Lemma 5.7 or in Lemma 5.8 are only "almost surely right continuous", resp. "almost surely continuous". Identify all steps in the proofs where this becomes relevant and...
-
The records of TNA Corporation at the end of 2020 provided the following data related to income taxes. - Unrealized gain on the company's investment portfolio, \(\$ 50,000\); recognized in net income...
-
SuperCity is a large retailer of electronics and appliances. The store sells three different models of TVs that are ordered from different manufacturers. The demands, costs, and storage requirements...
-
In the context of asset pricing, the finance literature impliesthat an investor will be indifferent between two bonds which showsequal yields to maturity if they are of similar default risk. Whatar 2...
-
Aggressive versus Conservative seasonal funding strategy Dynabase Tool has forecast its total funds requirement for the coming year as shown in the following table. a. Divide the firm's monthly funds...
-
Bramble Corp. reported net income of $88200 for the year ended December 31, 2021. Included in net income was a gain on early extinguishment of debt of $120000 related to bonds payable with a book...
-
TQM places the customer in the forefront of decision-making. It also looks at the concept of internal customer and supplier. It advocates that everyone in the organization is a customer and consumer...
-
Mr. Ironman sent an email to Mr. Spiderman and ask him Will you sell Unit # 801 of your Highrise apartment building, quote the lowest price. To which Mr. Spiderman replied, Lowest price for unit #801...
-
Critically assess two challenges a newly hired executive may face when devising a new CSR program for an organization during a crisis(e.g., covid). Explain with examples of a company that went...
-
On the surface, there are many challenges of team evaluations and their impact on team performance. From a broader organizational lens, organizations rely heavily on teams to collectively deliver a...
-
The New England PatriotsLinks to an external site. were the first National Football League (NFL) franchise to buy its own team aircraft. The Patriots purchased two Boeing 767 planes for a total of...
-
Select the organization and then Describe the importance of demand forecasting and the forecasting techniques used within the supply chain of your organization
-
H Corporation has a bond outstanding. It has a coupon rate of 8 percent and a $1000 par value. The bond has 6 years left to maturity but could be called after three years for $1000 plus a call...
-
Stroud and Freeman are general partners in Strouds Food Center, a grocery store. Nothing in the articles of partnership restricts the power or authority of either partner to act in respect to the...
-
Civil Code 1719, subdivision (a) provides in part that any person who draws a check that is dishonored due to insufficient funds shall be liable to the payee for the amount owing upon the check and...
-
Rachel bought a car from the Beautiful Used Car Agency under a written contract. She purchased the car in reliance on Beautifuls agents oral representations that it had never been in a wreck and...
-
How much are firms willing to sacrifice in income taxes in order to smooth earnings?
-
Do smaller firms tend to manage earnings when compared to larger firms?
-
Find the Internet site "The Fraud Farm." Prepare your own "Gallery of Weasels."
Study smarter with the SolutionInn App