package org.brain.bean;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlInputHidden;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import org.brain.dbo.DBOperate;
import org.brain.pojos.*;
@ManagedBean(name="searchshare")
@RequestScoped
public class SearchShare {
private String searchContext;
private int searchType = 1;
private List<Document> docList = new ArrayList<Document>();
int row = 0;
public void searchsTitle(){
docList = DBOperate.search("Document where title like '%"+searchContext+"%' and sharetg = 1");
row=docList.size();
}
public void searchsAuthor(){
docList = DBOperate.search("Document where author like '%"+searchContext+"%'and sharetg = 1 ");
row=docList.size();
}
public void searchsKeyword(){
docList = DBOperate.search("Document where keywords like '%"+searchContext+"%' and sharetg = 1");
row=docList.size();
}
public String searchshareAction()
{
docList.clear();
switch(searchType)
{
case 1:
System.out.println("searchType:"+searchType);searchsTitle();break;
case 2:
searchsAuthor();break;
case 3:
searchsKeyword();break;
}
return "/mySpace";
}
public SearchShare(){
/* FacesContext facesContext = FacesContext.getCurrentInstance();
authenticationBean = (authenticationBean)facesContext.getApplication().createValueBinding("#{authenticationBean}").getValue(facesContext);
//username = authenticationBean.getUsername();*/
//username = "liuyong";
/* Document document = (Document)DBOperate.search("User where username = "+username+"").get(0);
author = document.getAuthor();
keywords = document.getKeywords();
title = document.getTitle();*/
}
// public docList<Document> authordocList(){
// docList docList = DBOperate.search("Document where author like'&"+keyword+"&' order by createtime asc");
// return docList;
// }
//
// public docList<Document> keywordsdocList(){
// docList docList = DBOperate.search("Document where keywords like '&"+keyword+"&' order by createtime asc");
// return docList;
// }
//
// public void SearchdocList(ActionEvent event)
// {
// System.out.println("this is a test!");
// System.out.println(" value"+itemvalue);
// docList.clear();
// switch (itemvalue.charAt(0)) {
// case '1': //docList = titledocList();break;
//
//
// case '2'://docList= authordocList();break;
//
//
// case '3'://docList = keywordsdocList();break;
//
//
// default:docList= null;
//
// }
// //return "/search";
// }
public void validataInput(FacesContext context,
UIComponent component, Object value){
String text = value.toString();
if(text.equals("")){
throw new ValidatorException(new FacesMessage("查询内容不能为空!"));
}
}
public void checkItemvalue(FacesContext context,UIComponent component,Object obj){
String value = obj.toString();
if(value.equals(""))
{
throw new ValidatorException(new FacesMessage("请选择,查询类型!"));
}
}
public int getRow() {
return row;
}
public void setRow(int row) {
this.row = row;
}
public String getSearchContext() {
return searchContext;
}
public void setSearchContext(String searchContext) {
this.searchContext = searchContext;
}
public int getSearchType() {
return searchType;
}
public void setSearchType(int searchType) {
this.searchType = searchType;
}
public List<Document> getDocList() {
return docList;
}
public void setDocList(List<Document> docList) {
this.docList = docList;
}
}