fix messages
This commit is contained in:
parent
fa03edf32d
commit
6b90d7b0c0
@ -1,5 +1,27 @@
|
|||||||
package ru.ulstu.core.navigation;
|
package ru.ulstu.core.navigation;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
@Named
|
||||||
public class Page {
|
public class Page {
|
||||||
|
public static final String INDEX = "/index.xhtml";
|
||||||
public static final String PAPER_LIST = "/paper/papers.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
41
src/main/java/ru/ulstu/core/util/FacesUtil.java
Normal file
41
src/main/java/ru/ulstu/core/util/FacesUtil.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package ru.ulstu.paper.controller;
|
package ru.ulstu.paper.controller;
|
||||||
|
|
||||||
import ru.ulstu.core.navigation.Page;
|
import ru.ulstu.core.navigation.Page;
|
||||||
|
import ru.ulstu.core.util.FacesUtil;
|
||||||
import ru.ulstu.paper.model.Paper;
|
import ru.ulstu.paper.model.Paper;
|
||||||
import ru.ulstu.paper.service.PaperService;
|
import ru.ulstu.paper.service.PaperService;
|
||||||
import ru.ulstu.user.model.User;
|
import ru.ulstu.user.model.User;
|
||||||
@ -11,13 +12,14 @@ import javax.faces.context.FacesContext;
|
|||||||
import javax.faces.view.ViewScoped;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Named
|
@Named
|
||||||
@ViewScoped
|
@ViewScoped
|
||||||
public class PaperView {
|
public class PaperView implements Serializable {
|
||||||
@Inject
|
@Inject
|
||||||
private PaperService paperService;
|
private PaperService paperService;
|
||||||
|
|
||||||
@ -31,6 +33,7 @@ public class PaperView {
|
|||||||
Map<String, String> params = FacesContext.getCurrentInstance().
|
Map<String, String> params = FacesContext.getCurrentInstance().
|
||||||
getExternalContext().getRequestParameterMap();
|
getExternalContext().getRequestParameterMap();
|
||||||
paper = paperService.findPaperById(Integer.valueOf(params.get("id")));
|
paper = paperService.findPaperById(Integer.valueOf(params.get("id")));
|
||||||
|
FacesUtil.showInfoMessage("Статья открыта", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Paper getPaper() {
|
public Paper getPaper() {
|
||||||
@ -55,6 +58,7 @@ public class PaperView {
|
|||||||
|
|
||||||
public String save() {
|
public String save() {
|
||||||
paperService.save(paper);
|
paperService.save(paper);
|
||||||
return Page.PAPER_LIST;
|
FacesUtil.showInfoMessage("Статья сохранена", "");
|
||||||
|
return Page.PAPER_LIST + "?faces-redirect=true";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,29 +19,26 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<h:form id="mainForm">
|
<h:form id="mainForm">
|
||||||
<p:growl id="messages"/>
|
|
||||||
|
|
||||||
<div class="ui-g">
|
<div class="ui-g">
|
||||||
<div class="ui-g-2"></div>
|
<div class="ui-g-2"></div>
|
||||||
<div class="ui-g-8">
|
<div class="ui-g-8">
|
||||||
<p:menubar>
|
<p:menubar>
|
||||||
<p:menuitem>
|
<p:menuitem>
|
||||||
<h:link outcome="/index.xhtml">
|
<h:link outcome="#{page.INDEX}">
|
||||||
<h:graphicImage name="img/logo.png" height="30"/>
|
<h:graphicImage name="img/logo.png" height="30"/>
|
||||||
</h:link>
|
</h:link>
|
||||||
</p:menuitem>
|
</p:menuitem>
|
||||||
<p:submenu label="Статьи" icon="fa fa-file-text-o">
|
<p:submenu label="Статьи" icon="fa fa-file-text-o">
|
||||||
<p:menuitem value="Мои статьи" icon="fa fa-calendar" url="/paper/dashboard.xhtml"/>
|
<p:menuitem value="Мои статьи" icon="fa fa-calendar" url="#{page.DASHBOARD}"/>
|
||||||
<p:menuitem value="Все статьи" icon="fa fa-file-o" url="/paper/papers.xhtml"/>
|
<p:menuitem value="Все статьи" icon="fa fa-file-o" url="#{page.PAPER_LIST}"/>
|
||||||
</p:submenu>
|
</p:submenu>
|
||||||
|
|
||||||
<p:menuitem value="Quit" url="http://www.primefaces.org" icon="pi pi-times"/>
|
|
||||||
|
|
||||||
<f:facet name="options">
|
<f:facet name="options">
|
||||||
<p:link href="/logout" value="Выход"/>
|
<p:link href="#{page.LOGOUT}" value="Выход"/>
|
||||||
</f:facet>
|
</f:facet>
|
||||||
</p:menubar>
|
</p:menubar>
|
||||||
<div class="ui-fluid">
|
<div class="ui-fluid">
|
||||||
|
<p:growl id="messages"/>
|
||||||
<ui:insert name="content">Content</ui:insert>
|
<ui:insert name="content">Content</ui:insert>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -61,7 +61,8 @@
|
|||||||
itemLabel="#{author.userAbbreviate}"
|
itemLabel="#{author.userAbbreviate}"
|
||||||
itemValue="#{author}"/>
|
itemValue="#{author}"/>
|
||||||
</p:selectCheckboxMenu>
|
</p:selectCheckboxMenu>
|
||||||
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"/>
|
<p:commandButton action="#{paperView.save}" value="Сохранить" ajax="true" process="@form"
|
||||||
|
update="messages"/>
|
||||||
</h:panelGrid>
|
</h:panelGrid>
|
||||||
<p:panelGrid columns="1">
|
<p:panelGrid columns="1">
|
||||||
<p:link href="/conference/conferenceList.xhtml" value="Статья участвует в конференции"/>
|
<p:link href="/conference/conferenceList.xhtml" value="Статья участвует в конференции"/>
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" layout:fragment="content">
|
|
||||||
<section id="services">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 text-center">
|
|
||||||
<h2 class="section-heading text-uppercase">Доступ запрещен</h2>
|
|
||||||
<a href="/"><h3>Вернуться на главную</h3></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,21 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" layout:fragment="content">
|
|
||||||
<section id="services">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 text-center">
|
|
||||||
<h2 class="section-heading text-uppercase">Страница не найдена</h2>
|
|
||||||
<a href="/"><h3>Вернуться на главную</h3></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,21 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container" layout:fragment="content">
|
|
||||||
<section id="services">
|
|
||||||
<div class="container">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-lg-12 text-center">
|
|
||||||
<h2 class="section-heading text-uppercase">Ошибка сервера</h2>
|
|
||||||
<a href="/"><h3>Вернуться на главную</h3></a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in New Issue
Block a user