Following my last blog post, I am continuing my open source contributions on E-commerce-project-springBoot. This project is an e-commerce webapp which uses Java Spring Boot and MySQL.
This week I have raised a new issue and created a PR with the fix. I discovered this issue over a week ago, however I was not able to find a fix right away. This week I managed to figure out the cause of the issue. Thankfully, I have worked enough with this project to understand the project structure and Spring Boot objects and functions, because I do not think I would have been able to debug this if it were my first look into this project. I'm finding it very beneficial to contribute to a project continuously rather than jumping from project to project with every single pull request.
The Issue: Update button on products page does not work
Cause of the Issue:
- when the update button in products page is clicked, it triggers
updateproduct()
inAdminController.java
- updateproduct() creates a new "productsUpdate" ModelAndView and adds a product object and list of category objects to the ModelAndView
- the resulting ModelAndView is displayed to the user
- the ModelAndView can be found in
productsUpdate.jsp
- the code
<c:forEach var="product" items="products">
is causing the error to be thrown since it should be items="${products}" and not a string
- the code
- there is no need for the forEach loop since we never add a list of products to the ModelAndView, only one product object
- keeping the forEach loop results in blank page, since we never pass in a list of products
Fix:
- in
productsUpdate.jsp
, removed the forEach loop completely, since we add one product to the view and not a list of products
Fix Tested:
PR: Fixed Update button in Products page
What I Learned
- How to debug Java programs using IntelliJ and breakpoints
- Used this to determine that the exception was thrown while rendering the ModelAndView
productsUpdate.jsp
and not theupdateproduct()
function
- Used this to determine that the exception was thrown while rendering the ModelAndView
- How to read Java server logs to troubleshoot exceptions
- Used this to figure out that in
productsUpdate.jsp
product was a string even though we were expecting a list
- Used this to figure out that in
- Gained more in-depth knowledge about Java Spring Framework by reading official documentation
- The ModelAndView class holds both Model and View in the web MVC framework.
- Using the addObject we can add an attribute to the model
Even though the update button now displayed the correct page with the correct data to be updated, there is still a bug when trying to finish the information update by clicking Update Details in that page. I plan to work on this in a future PR.
Top comments (0)