From d741bd019a31e02bcb4692f12de7ced61c821f52 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sun, 24 Nov 2019 20:55:16 +0400 Subject: [PATCH] display authors --- .../ru/ulstu/paper/controller/PaperView.java | 9 +++++++ .../ulstu/user/controller/UserConverter.java | 26 +++++++++++++++++++ .../META-INF/resources/paper/paper.xhtml | 10 +++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/java/ru/ulstu/user/controller/UserConverter.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperView.java b/src/main/java/ru/ulstu/paper/controller/PaperView.java index b4b87ea..ea9df8b 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperView.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperView.java @@ -3,6 +3,8 @@ package ru.ulstu.paper.controller; import ru.ulstu.core.navigation.Page; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; import javax.annotation.PostConstruct; import javax.faces.context.FacesContext; @@ -19,6 +21,9 @@ public class PaperView { @Inject private PaperService paperService; + @Inject + private UserService userService; + private Paper paper; @PostConstruct @@ -44,6 +49,10 @@ public class PaperView { return Arrays.asList(Paper.PaperType.values()); } + public List getAuthors() { + return userService.findAll(); + } + public String save() { paperService.save(paper); return Page.PAPER_LIST; diff --git a/src/main/java/ru/ulstu/user/controller/UserConverter.java b/src/main/java/ru/ulstu/user/controller/UserConverter.java new file mode 100644 index 0000000..61997f4 --- /dev/null +++ b/src/main/java/ru/ulstu/user/controller/UserConverter.java @@ -0,0 +1,26 @@ +package ru.ulstu.user.controller; + +import org.springframework.stereotype.Service; +import ru.ulstu.user.model.User; +import ru.ulstu.user.service.UserService; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Inject; + +@Service +public class UserConverter implements Converter { + @Inject + private UserService userService; + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return value == null ? null : userService.findById(Integer.valueOf(value)); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return ((User) value).getId().toString(); + } +} diff --git a/src/main/resources/META-INF/resources/paper/paper.xhtml b/src/main/resources/META-INF/resources/paper/paper.xhtml index c7e3cec..20fff13 100644 --- a/src/main/resources/META-INF/resources/paper/paper.xhtml +++ b/src/main/resources/META-INF/resources/paper/paper.xhtml @@ -32,6 +32,16 @@ + + + + + +