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.context.FacesContext;
import javax.faces.validator.ValidatorException;
import org.brain.dbo.DBOperate;
import org.brain.pojos.Document;
@ManagedBean(name="search")
@RequestScoped
public class SearchDOC {
private String searchContext;
private int searchType = 1;
private authenticationBean authenticationBean;
private List<Document> docList = new ArrayList();
public List<Document> searchTitle(){
docList = DBOperate.search("Document where title like '%"+searchContext+"%'");
return docList;
}
public List<Document> searchAuthor(){
docList = DBOperate.search("Document where author like '%"+searchContext+"%'");
return docList;
}
public List<Document> searchKeyword(){
docList = DBOperate.search("Document where keywords like '%"+searchContext+"%'");
return docList;
}
public String searchAction()
{
docList.clear();
switch(searchType)
{
case 1:
System.out.println("searchType:"+searchType);searchTitle();break;
case 2:
searchAuthor();break;
case 3:
searchKeyword();break;
}
return "/search";
}
public SearchDOC(){
}
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 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;
}
}