display authors

This commit is contained in:
Anton Romanov 2019-11-24 20:55:16 +04:00
parent 846d94bb46
commit d741bd019a
3 changed files with 45 additions and 0 deletions

View File

@ -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<User> getAuthors() {
return userService.findAll();
}
public String save() {
paperService.save(paper);
return Page.PAPER_LIST;

View File

@ -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();
}
}

View File

@ -32,6 +32,16 @@
<p:outputLabel for="@next" value="Комментарий:"/>
<p:textEditor widgetVar="editor2" value="#{paperView.paper.comment}" height="300"
style="margin-bottom:10px" placeholder="Комментарий"/>
<p:outputLabel for="@next" value="Авторы:"/>
<p:selectCheckboxMenu id="authors" value="#{paperView.paper.authors}" multiple="true"
converter="#{userConverter}">
<f:attribute name="collectionType" value="java.util.HashSet"/>
<f:selectItems value="#{paperView.authors}"
var="author"
itemLabel="#{author.userAbbreviate}"
itemValue="#{author}"/>
</p:selectCheckboxMenu>
</h:panelGrid>
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"/>
</p:panel>