Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
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_weekendowa_20221008
Commits
d79bd36b
Commit
d79bd36b
authored
Nov 26, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redirect po poprawnym zapisaniu produktu
parent
8b0dd8ea
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+7
-3
No files found.
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
d79bd36b
...
@@ -105,15 +105,19 @@ public class ProductController {
...
@@ -105,15 +105,19 @@ public class ProductController {
// Metoda jest wywoływana zawsze, a to programista ma sprawdzić czy walidacja się powiodła.
// Metoda jest wywoływana zawsze, a to programista ma sprawdzić czy walidacja się powiodła.
// W BindingResult znajdują się też informacje o błędach.
// W BindingResult znajdują się też informacje o błędach.
if
(
bindingResult
.
hasErrors
())
{
if
(
bindingResult
.
hasErrors
())
{
model
.
addAttribute
(
"errors"
,
bindingResult
.
getAllErrors
());
// model.addAttribute("errors", bindingResult.getAllErrors());
// błędów już nie dodajemy oddzielne, bo będą wyświeltlone przez f:error
// ponownie wyświetlamy formularz
return
"product_form"
;
}
else
try
{
}
else
try
{
// Gdy próbujemy wywołać save, a obiekt nie spełnia wymagań validation, to wtedy Hibernate zablokuje taki zapis (wyrzuci wyjątek).
// Gdy próbujemy wywołać save, a obiekt nie spełnia wymagań validation, to wtedy Hibernate zablokuje taki zapis (wyrzuci wyjątek).
productRepository
.
save
(
product
);
productRepository
.
save
(
product
);
model
.
addAttribute
(
"saved"
,
true
);
// Po pomyślnym zapisaniu przechodzimy na stronę tego produktu
return
"redirect:/products/"
+
product
.
getProductId
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
model
.
addAttribute
(
"errors"
,
ExceptionUtils
.
allMessages
(
e
));
model
.
addAttribute
(
"errors"
,
ExceptionUtils
.
allMessages
(
e
));
return
"product_form"
;
}
}
return
"product_form"
;
}
}
}
}
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