/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.evasion.client.controler.admin;
import com.evasion.ejb.local.StaticPageManagerLocal;
import com.evasion.entity.content.StaticPage;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIData;
import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author sebastien.glon
*/
@ManagedBean
@RequestScoped
public class AdminStaticPage {
private static final Logger LOGGER = LoggerFactory.getLogger(AdminStaticPage.class.getName());
@EJB
StaticPageManagerLocal ejb;
private List<StaticPage> pages;
private UIData selectedRow;
@PostConstruct
public void initBean() {
FacesContext ctx = FacesContext.getCurrentInstance();
ctx.getExternalContext().getSessionMap().remove("currentStaticPage");
List<StaticPage> list = ejb.listAll();
pages = ( list.isEmpty() ) ? null : list;
}
public String doNew() {
LOGGER.debug("Deamnde de création, d'une nouvelle page statique");
FacesContext ctx = FacesContext.getCurrentInstance();
StaticPage page = new StaticPage("", "<h1>Page en construction</h1><br>Mon corps de texte<br>", "", null);
ctx.getExternalContext().getSessionMap().put("currentStaticPage", page);
return "staticpageForm.xhtml";
}
public String doEdit() {
FacesContext ctx = FacesContext.getCurrentInstance();
StaticPage page = (StaticPage) selectedRow.getRowData();
ctx.getExternalContext().getSessionMap().put("currentStaticPage", page);
LOGGER.debug("Deamnde d'édition, de la page statique id {}", page.getId());
return "staticpageForm.xhtml";
}
public String doAppercu() {
FacesContext fctx = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = fctx.getViewRoot();
viewRoot.getViewMap().put("appercuCorpPage", ( (StaticPage) selectedRow.getRowData() ).getCorps());
return "Success";
}
public String doSupr() {
ejb.deletePage((StaticPage) selectedRow.getRowData());
return "Success";
}
//----------- Getter Setter --------------------------//
public List<StaticPage> getPages() {
return pages;
}
public void setPages(List<StaticPage> pages) {
this.pages = pages;
}
public UIData getSelectedRow() {
return selectedRow;
}
public void setSelectedRow(UIData selectedRow) {
this.selectedRow = selectedRow;
}
public String getPage() {
FacesContext fctx = FacesContext.getCurrentInstance();
UIViewRoot viewRoot = fctx.getViewRoot();
return (String) viewRoot.getViewMap().get("appercuCorpPage");
}
}