diff --git a/src/main/java/ru/ulstu/core/navigation/Page.java b/src/main/java/ru/ulstu/core/navigation/Page.java index b43cc46..754ab8d 100644 --- a/src/main/java/ru/ulstu/core/navigation/Page.java +++ b/src/main/java/ru/ulstu/core/navigation/Page.java @@ -1,5 +1,27 @@ package ru.ulstu.core.navigation; +import javax.inject.Named; + +@Named public class Page { + public static final String INDEX = "/index.xhtml"; public static final String PAPER_LIST = "/paper/papers.xhtml"; + public static final String DASHBOARD = "/paper/dashboard.xhtml"; + public static final String LOGOUT = "/logout"; + + public String getPAPER_LIST() { + return PAPER_LIST; + } + + public String getINDEX() { + return INDEX; + } + + public String getDASHBOARD() { + return DASHBOARD; + } + + public String getLOGOUT() { + return LOGOUT; + } } diff --git a/src/main/java/ru/ulstu/core/util/FacesUtil.java b/src/main/java/ru/ulstu/core/util/FacesUtil.java new file mode 100644 index 0000000..7b63ceb --- /dev/null +++ b/src/main/java/ru/ulstu/core/util/FacesUtil.java @@ -0,0 +1,41 @@ +package ru.ulstu.core.util; + +import javax.faces.FacesException; +import javax.faces.application.FacesMessage; +import javax.faces.context.ExternalContext; +import javax.faces.context.FacesContext; +import java.io.IOException; + +public class FacesUtil { + public static void redirectToPage(FacesContext context, String page, String params) { + ExternalContext extContext = context.getExternalContext(); + String url = extContext.encodeActionURL(context.getApplication().getViewHandler().getActionURL(context, page) + + params); + try { + extContext.redirect(url); + } catch (IOException e) { + throw new FacesException(e); + } + } + + public static void redirectToPage(String page) { + redirectToPage(FacesContext.getCurrentInstance(), page, ""); + } + + public static void redirectToPage(String page, String params) { + redirectToPage(FacesContext.getCurrentInstance(), page, params); + } + + public static void showInfoMessage(String summary, String detail) { + FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary, detail); + FacesContext fc = FacesContext.getCurrentInstance(); + fc.getExternalContext().getFlash().setKeepMessages(true); + fc.addMessage(null, message); + } + + public static void showDangerMessage(String summary, String detail) { + FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, detail); + FacesContext.getCurrentInstance().addMessage(null, message); + } + +} diff --git a/src/main/java/ru/ulstu/paper/controller/PaperView.java b/src/main/java/ru/ulstu/paper/controller/PaperView.java index ea9df8b..c00f9cf 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperView.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperView.java @@ -1,6 +1,7 @@ package ru.ulstu.paper.controller; import ru.ulstu.core.navigation.Page; +import ru.ulstu.core.util.FacesUtil; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -11,13 +12,14 @@ import javax.faces.context.FacesContext; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; +import java.io.Serializable; import java.util.Arrays; import java.util.List; import java.util.Map; @Named @ViewScoped -public class PaperView { +public class PaperView implements Serializable { @Inject private PaperService paperService; @@ -31,6 +33,7 @@ public class PaperView { Map params = FacesContext.getCurrentInstance(). getExternalContext().getRequestParameterMap(); paper = paperService.findPaperById(Integer.valueOf(params.get("id"))); + FacesUtil.showInfoMessage("Статья открыта", ""); } public Paper getPaper() { @@ -55,6 +58,7 @@ public class PaperView { public String save() { paperService.save(paper); - return Page.PAPER_LIST; + FacesUtil.showInfoMessage("Статья сохранена", ""); + return Page.PAPER_LIST + "?faces-redirect=true"; } } diff --git a/src/main/resources/META-INF/resources/basicTemplate.xhtml b/src/main/resources/META-INF/resources/basicTemplate.xhtml index 0e92956..641d09b 100644 --- a/src/main/resources/META-INF/resources/basicTemplate.xhtml +++ b/src/main/resources/META-INF/resources/basicTemplate.xhtml @@ -19,29 +19,26 @@ } - -
- + - - + + - - - +
+ Content
diff --git a/src/main/resources/META-INF/resources/paper/paper.xhtml b/src/main/resources/META-INF/resources/paper/paper.xhtml index a1ee9d2..938754c 100644 --- a/src/main/resources/META-INF/resources/paper/paper.xhtml +++ b/src/main/resources/META-INF/resources/paper/paper.xhtml @@ -61,7 +61,8 @@ itemLabel="#{author.userAbbreviate}" itemValue="#{author}"/> - + diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html deleted file mode 100644 index a80b444..0000000 --- a/src/main/resources/templates/error/403.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Доступ запрещен

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/error/404.html b/src/main/resources/templates/error/404.html deleted file mode 100644 index 8f1d80b..0000000 --- a/src/main/resources/templates/error/404.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Страница не найдена

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file diff --git a/src/main/resources/templates/error/500.html b/src/main/resources/templates/error/500.html deleted file mode 100644 index f89b83a..0000000 --- a/src/main/resources/templates/error/500.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - -
-
-
-
-
-

Ошибка сервера

-

Вернуться на главную

-
-
-
-
-
- - \ No newline at end of file