package org.brain.bean;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.validator.ValidatorException;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.brain.dbo.DBOperate;
import org.brain.pojos.Document;
import org.brain.pojos.Documenttype;
import org.brain.pojos.Treemenu;
import org.brain.pojos.User;
import org.brain.tool.ToolBean;
@ManagedBean(name="modifyDocument")
@RequestScoped
public class ModifyDocumentBean {
static int id;
private Document document;
private int documentid;
@ManagedProperty(value = "#{documentType}")
private documentTypeBean documenttype;
@ManagedProperty(value = "#{selectBean}")
private SelectBean treemenu;
private String author;
private Date years;
private String title;
private String link;
private String secondauthor;
private String secondtitle;
private String placeofpublication;
private String press;
private String serialnumber;
private Integer pagenumber;
private String referencescited;
private double version;
private Date date;
private String simpletitle;
private String isbn;
private String classify;
private String label;
private String keywords;
private String themewords;
private String summary;
private String note;
private String image;
private String language;
private Date lastsearchtime;
private Date createtime;
private Date edittime;
private String message;
private String filePath;
private boolean flag;
// Constructors
/** default constructor */
public ModifyDocumentBean() {
}
public Integer getDocumentid() {
return this.documentid;
}
public void setDocumentid(Integer documentid) {
this.documentid = documentid;
}
public documentTypeBean getDocumenttype() {
return documenttype;
}
public void setDocumenttype(documentTypeBean documenttype) {
this.documenttype = documenttype;
}
public SelectBean getTreemenu() {
return this.treemenu;
}
public void setTreemenu(SelectBean treemenu) {
this.treemenu = treemenu;
}
public String getAuthor() {
return this.author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getYears() {
return this.years;
}
public void setYears(Date years) {
this.years = years;
}
public String getTitle() {
initdoc_update();
return this.title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLink() {
return this.link;
}
public void setLink(String link) {
this.link = link;
}
public String getSecondauthor() {
return this.secondauthor;
}
public void setSecondauthor(String secondauthor) {
this.secondauthor = secondauthor;
}
public String getSecondtitle() {
return this.secondtitle;
}
public void setSecondtitle(String secondtitle) {
this.secondtitle = secondtitle;
}
public String getPlaceofpublication() {
return this.placeofpublication;
}
public void setPlaceofpublication(String placeofpublication) {
this.placeofpublication = placeofpublication;
}
public String getPress() {
return this.press;
}
public void setPress(String press) {
this.press = press;
}
public String getSerialnumber() {
return this.serialnumber;
}
public void setSerialnumber(String serialnumber) {
this.serialnumber = serialnumber;
}
public Integer getPagenumber() {
return this.pagenumber;
}
public void setPagenumber(Integer pagenumber) {
this.pagenumber = pagenumber;
}
public String getReferencescited() {
return this.referencescited;
}
public void setReferencescited(String referencescited) {
this.referencescited = referencescited;
}
public double getVersion() {
return this.version;
}
public void setVersion(double version) {
this.version = version;
}
public Date getDate() {
return this.date;
}
public void setDate(Date date) {
this.date = date;
}
public String getSimpletitle() {
return this.simpletitle;
}
public void setSimpletitle(String simpletitle) {
this.simpletitle = simpletitle;
}
public String getIsbn() {
return this.isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getClassify() {
return this.classify;
}
public void setClassify(String classify) {
this.classify = classify;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
public String getKeywords() {
return this.keywords;
}
public void setKeywords(String keywords) {
this.keywords = keywords;
}
public String getThemewords() {
return this.themewords;
}
public void setThemewords(String themewords) {
this.themewords = themewords;
}
public String getSummary() {
return this.summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getNote() {
return this.note;
}
public void setNote(String note) {
this.note = note;
}
public String getImage() {
return this.image;
}
public void setImage(String image) {
this.image = image;
}
public String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
this.language = language;
}
public Date getLastsearchtime() {
return this.lastsearchtime;
}
public void setLastsearchtime(Date lastsearchtime) {
this.lastsearchtime = lastsearchtime;
}
public Date getCreatetime() {
return this.createtime;
}
public void setCreatetime(Date createtime) {
this.createtime = createtime;
}
public Date getEdittime() {
return this.edittime;
}
public void setEdittime(Date edittime) {
this.edittime = edittime;
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public Document getDoc() {
return document;
}
public void setDoc(Document document) {
this.document = document;
}
public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public void setDocumentid(int documentid) {
this.documentid = documentid;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public String updateDocument()
{
flag=false;
FacesContext facesContext = FacesContext.getCurrentInstance();
documenttype = (documentTypeBean) facesContext.getApplication()
.getVariableResolver().resolveVariable(facesContext, "documentType");
treemenu = (SelectBean) facesContext.getApplication().getVariableResolver()
.resolveVariable(facesContext, "selectBean");
System.out.println("treeMenu "+treemenu.getCurrentType1());
System.out.println("documenttype "+documenttype.getTypeId());
Treemenu treeMenu = DBOperate.getTreeMenu(Integer.parseInt(treemenu.getCurrentType1()));
Documenttype documentType = DBOperate.getDocumenttype(Integer.parseInt(documenttype.getTypeId()));
document.setTreemenu(treeMenu);
document.setDocumenttype(documentType);
document.setAuthor(author);
document.setTitle(title);
document.setKeywords(keywords);
document.setThemewords(themewords);
document.setSummary(summary);
document.setClassify(classify);
document.setYears(years);
document.setLink(link);
document.setSecondauthor(secondauthor);
document.setSecondtitle(secondtitle);
document.setPlaceofpublication(placeofpublication);
document.setPress(press);
document.setSerialnumber(serialnumber);
document.setPagenumber(pagenumber);
document.setReferencescited(referencescited);
document.setVersion(version);
document.setDate(date);
document.setSimpletitle(simpletitle);
document.setIsbn(isbn);
document.setLabel(label);
document.setNote(note);
//修改用户名称
User user = ToolBean.getUserSession();
document.setImage("pic/"+user.getUsername()+"/"+image);
document.setLanguage(language);
//document.setLastsearchtime(new Date());
document.setEdittime(new Date());
System.out.println("this is a test panel!");
flag = DBOperate.update(document);
return "/modifyDocumentResult";
}
public void initdoc_update()
{
String requestId = ToolBean.getRequestParameter("id");
if(requestId!=null){
documentid = Integer.parseInt(requestId);
id = documentid;
document = DBOperate.getDocument(documentid);
}
else{
document = DBOperate.getDocument(id);
}
author = document.getAuthor();
years = document.getYears();
title = document.getTitle();
link = document.getLink();
secondauthor = document.getSecondauthor();
secondtitle = document.getSecondtitle();
placeofpublication = document.getPlaceofpublication();
press = document.getPress();
serialnumber = document.getSerialnumber();
pagenumber = document.getPagenumber();
referencescited = document.getReferencescited();
version = document.getVersion();
date = document.getDate();
simpletitle = document.getSimpletitle();
isbn = document.getIsbn();
classify = document.getClassify();
label = document.getLabel();
keywords = document.getKeywords();
themewords = document.getThemewords();
summary = document.getSummary();
note = document.getNote();
language = document.getLanguage();
lastsearchtime = document.getLastsearchtime();
createtime = document.getCreatetime();
edittime = document.getEdittime();
}
public void validateInput(FacesContext context,
UIComponent component, Object value){
String text = value.toString();
if(text.equals("")){
throw new ValidatorException(new FacesMessage(" 内容不能为空!"));
}
}
}