Package org.mapache.ui.admin

Source Code of org.mapache.ui.admin.AdminBlogManagementBean

package org.mapache.ui.admin;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.component.html.HtmlDataTable;

import javax.faces.context.FacesContext;

import org.mapache.business.BusinessController;
import org.mapache.business.MapacheException;
import org.mapache.business.blog.Blog;
import org.mapache.ui.common.MapacheUIUtils;

public class AdminBlogManagementBean {
    private BusinessController _bcControl;
    private List<Blog> _blogs;
    private Blog _blog;
    private HtmlDataTable _blogTable;
    private boolean _editMode=false,_createMode=true;
    private String _title,_description;
   
    public AdminBlogManagementBean() {
    }
   
    private BusinessController getBusinessController(){
        if(_bcControl==null){
            _bcControl = new BusinessController();
        }
        return _bcControl;
    }
   
    public String editBlog() {
        _editMode = true;
        _blog = (Blog)_blogTable.getRowData();
        return "editClicked";
    }
    public String saveBlog() {
        try{
            getBusinessController().saveBlog(_blog);
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,MapacheUIUtils.getTranslation("info_blog_saved",null),MapacheUIUtils.getTranslation("info_blog_saved",null)));
            _editMode = false;
        }
        catch (MapacheException e) {
            // TODO log error message into file
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_blog_saved",null),MapacheUIUtils.getTranslation("error_blog_saved",null)));
            _editMode = true;
        }
        return "saveClicked";
    }

    public String cancel() {
        _editMode = false;
        FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,MapacheUIUtils.getTranslation("info_operation_canceled",null),MapacheUIUtils.getTranslation("info_operation_canceled",null)));
        return "cancelClicked";
    }

    public String deleteBlog() {
        try{
            getBusinessController().deleteBlog(_blog);
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,MapacheUIUtils.getTranslation("info_blog_deleted",null),MapacheUIUtils.getTranslation("info_blog_deleted",null)));
            _editMode= false;
        }
        catch(MapacheException e){
            // TODO log error message into file
            _editMode =true;
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_blog_deleted",null),MapacheUIUtils.getTranslation("error_blog_deleted",null)));
        }
        return "deleteClicked";
    }
    public String createBlog() {
        Blog newBlog = new Blog();
        newBlog.setTitle(_title);
        newBlog.setDescription(_description);
        try {
            getBusinessController().createBlog(newBlog);
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,MapacheUIUtils.getTranslation("info_blog_created",null),MapacheUIUtils.getTranslation("info_blog_created",null)));
            _createMode = false;
        } catch (MapacheException e) {
             FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_blog_created",null),MapacheUIUtils.getTranslation("error_blog_created",null)));
             _createMode = true;
             e.printStackTrace();
        }
        return "createClicked";
    }
    public String ok() {
        _title = _description = null;
        _createMode=true;
        return "okClicked";
    }
    public void setBlogs(List<Blog> blogs) {
        this._blogs = blogs;
    }

    public List<Blog> getBlogs() {
        try {
            _blogs = getBusinessController().loadAllBlogs();
        } catch (MapacheException e) {
             // TODO log error message into file
            e.printStackTrace();
        }
        return _blogs;
    }

    public void setBlog(Blog blog) {
        this._blog = blog;
    }

    public Blog getBlog() {
        return _blog;
    }

    public void setBlogTable(HtmlDataTable blogTable) {
        this._blogTable = blogTable;
    }

    public HtmlDataTable getBlogTable() {
        return _blogTable;
    }

    public void setEditMode(boolean editMode) {
        this._editMode = editMode;
    }

    public boolean isEditMode() {
        return _editMode;
    }

    public void setTitle(String title) {
        this._title = title;
    }

    public String getTitle() {
        return _title;
    }

    public void setDescription(String description) {
        this._description = description;
    }

    public String getDescription() {
        return _description;
    }

    public void setCreateMode(boolean createMode) {
        this._createMode = createMode;
    }

    public boolean isCreateMode() {
        return _createMode;
    }
}
TOP

Related Classes of org.mapache.ui.admin.AdminBlogManagementBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.