Package org.mapache.ui.admin

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

package org.mapache.ui.admin;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;

import javax.faces.validator.ValidatorException;

import org.mapache.business.BusinessController;
import org.mapache.business.MapacheException;
import org.mapache.business.blog.Blog;
import org.mapache.business.reply.Reply;
import org.mapache.business.topic.Topic;
import org.mapache.ui.common.MapacheUIUtils;

public class AdminReplyManagementBean {
    private BusinessController _bcControl;
    private boolean _editMode=false,_createMode=true;
    private String _content,_author,_email,_homepage;
    private Topic _topic;
   
    public AdminReplyManagementBean() {
    }
    private BusinessController getBusinessController(){
        if(_bcControl==null){
            _bcControl = new BusinessController();
        }
        return _bcControl;
    }

    public List<SelectItem> getTopicSelectItems(){
        List<SelectItem> topicSelectItems = new ArrayList<SelectItem>();
        List<Topic> topics;
        Blog b = new Blog();
        b.setBlogID(-1);
        Topic tr = new Topic();
        tr.setTopicID(-1);
        tr.setTitle(MapacheUIUtils.getTranslation("pleaseSelect",null));
        topicSelectItems.add(0,new SelectItem(tr, tr.getTitle(), String.valueOf(tr.getTopicID())));
        if(_topic==null){
            _topic = tr;
        }
        try{
            topics = getBusinessController().loadTopicsOfBlog(b);
            for(Iterator it = topics.iterator();it.hasNext();){
                Topic t = (Topic)it.next();
                topicSelectItems.add(new SelectItem(t,t.getTitle(),String.valueOf(t.getTopicID())));
            }
        }
        catch(MapacheException e){
            e.printStackTrace();   
        }
        return topicSelectItems;
    }
    public void setCreateMode(boolean createMode) {
        this._createMode = createMode;
    }

    public boolean isCreateMode() {
        return _createMode;
    }

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

    public boolean isEditMode() {
        return _editMode;
    }

    public void setContent(String content) {
        this._content = content;
    }

    public String getContent() {
        return _content;
    }

    public void setAuthor(String author) {
        this._author = author;
    }

    public String getAuthor() {
        return _author;
    }

    public void setEmail(String email) {
        this._email = email;
    }

    public String getEmail() {
        return _email;
    }

    public void setHomepage(String homepage) {
        this._homepage = homepage;
    }

    public String getHomepage() {
        return _homepage;
    }

    public void setTopic(Topic topic) {
        this._topic = topic;
    }

    public Topic getTopic() {
        return _topic;
    }

    public void validateTopic(FacesContext facesContext,
                              UIComponent uiComponent, Object object) {
         Topic t =(Topic)object;
         if(t.getTopicID()==-1){
             throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_please_select_topic",null),MapacheUIUtils.getTranslation("error_please_select_topic",null)),null);
         }
    }

    public String createReply() {
        Reply newReply = new Reply();
        newReply.setContent(_content);
        newReply.setUserEmail(_email);
        newReply.setUserName(_author);
        newReply.setUserHomePage(_homepage);
        try {
            getBusinessController().createReply(newReply,_topic.getTopicID());
            FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,MapacheUIUtils.getTranslation("info_reply_created",null),MapacheUIUtils.getTranslation("info_reply_created",null)));
            _createMode = false;
        } catch (MapacheException e) {
             FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR,MapacheUIUtils.getTranslation("error_reply_created",null),MapacheUIUtils.getTranslation("error_reply_created",null)));
             _createMode = true;
             e.printStackTrace();
        }
        return "createClicked";
    }

    public String ok() {
        _content = _author = _email = _homepage = null;
        _topic= null;
        _createMode=true;
        return "okClicked";
    }
}
TOP

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

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.