Commit e67567ac by Patryk Czarnik

Wypisywanie błędów na stronie formularza

parent 081e6cec
......@@ -74,9 +74,15 @@ public class ProductController {
// Spring sam wpisze dane do pól o takich samych nazwach.
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
System.out.println("Obiekt przed zapisem: " + product.getProductId() + " " + product.getProductName());
productRepository.save(product);
System.out.println("Obiekt po zapisie: " + product.getProductId() + " " + product.getProductName());
try {
System.out.println("Obiekt przed zapisem: " + product.getProductId() + " " + product.getProductName());
productRepository.save(product);
System.out.println("Obiekt po zapisie: " + product.getProductId() + " " + product.getProductName());
model.addAttribute("saved", true);
} catch (Exception e) {
model.addAttribute("errors", List.of(e));
}
return "product_form";
}
}
......@@ -41,6 +41,21 @@
</table>
</form>
<c:if test="${not empty(errors)}">
<div class="error">
<h4>Błędy:</h4>
<ul>
<c:forEach var="error" items="${errors}">
<li>${error}</li>
</c:forEach>
</ul>
</div>
</c:if>
<c:if test="${saved}">
<div class="info">Zapisano produkt nr ${product.productId}</div>
</c:if>
<div class="action"><a href="/products">powrót do listy produktów</a></div>
<div class="action"><a href="/">powrót do spisu treści</a></div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment