Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_dzienna_15_09
Commits
cdac874d
Commit
cdac874d
authored
Oct 05, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wyświetlanie błędów zapisu w razie ich wystąpienia
parent
36cc581b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
5 deletions
+33
-5
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+9
-4
product_form.jsp
...Spring/src/main/webapp/WEB-INF/templates/product_form.jsp
+24
-1
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
cdac874d
...
...
@@ -66,10 +66,15 @@ public class ProductController {
// Taki parametr od razu staje się częścią modelu (to jest tzw. ModelAttribute)
// i nie trzeba dodawać go w osobnym poleceniu.
System
.
out
.
println
(
"Produkt przed zapisem: "
+
product
);
productRepository
.
save
(
product
);
System
.
out
.
println
(
"Produkt po zapisie : "
+
product
);
try
{
System
.
out
.
println
(
"Produkt przed zapisem: "
+
product
);
productRepository
.
save
(
product
);
System
.
out
.
println
(
"Produkt po zapisie : "
+
product
);
model
.
addAttribute
(
"saved"
,
true
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Produkt bez zapisu : "
+
product
);
model
.
addAttribute
(
"errors"
,
List
.
of
(
e
.
toString
()));
}
return
"product_form"
;
}
...
...
PC30-SklepSpring/src/main/webapp/WEB-INF/templates/product_form.jsp
View file @
cdac874d
...
...
@@ -8,7 +8,15 @@
<link
rel=
"stylesheet"
type=
"text/css"
href=
"/styl.css"
>
</head>
<body>
<h1>
Edycja produktu
</h1>
<c:choose>
<c:when
test=
"${not empty(product.productId)}"
>
<h1>
Edycja produktu nr ${product.productId}
</h1>
</c:when>
<c:otherwise>
<h1>
Edycja nowego produktu
</h1>
</c:otherwise>
</c:choose>
<form
id=
"product-form"
method=
"post"
>
<table
class=
"form"
>
...
...
@@ -41,6 +49,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>
<p>
[
<a
href=
"/products"
>
powrót do listy produktów
</a>
]
</p>
<p>
[
<a
href=
"/"
>
powrót do spisu treści
</a>
]
</p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment