O que estou fazendo errado? ja pesquisei em outros tópicos, mas até agora não obtive sucesso!
Meu código DAO:
public List<RamalBean> busca(RamalBean ramalBean) {
this.session = MySQLDAOFactory.getSession();
Criteria criteria = session.createCriteria(RamalBean.class)
.add(Restrictions.like("busca", ramalBean.toString(), MatchMode.ANYWHERE).ignoreCase());
criteria.addOrder(Order.asc("setor").ignoreCase());
this.session.close();
return criteria.list();
}
Meu JSP index.jsp:
<table>
<tr>
<td align="center">
<s:form action="select" method="post">
<s:textfield required="true" theme="ajax" id="busca" name="" label="Busca" size="25" />
<s:submit action="select" value="Buscar" name="aux" notifyTopics="buscaTopic" />
</s:form></td>
</tr>
</table>
<s:div id="buscaList" href="select.action" listenTopics="buscaTopic"
theme="ajax" />
Struts.xml:
<action name="select" method="busca"
class="br.com.listafag.actions.RamalAction">
<result name="true">/busca.jsp</result>
</action>
Na minha Action tenho o seguinte código:
private List<RamalBean> select = new ArrayList<RamalBean>();
public String busca() {
setListaRamal(ramalDAO.busca(getRamalBean()));
return "true";
}
Meu JSP busca.jsp:
<table>
<tr>
<td width="135px" style="color: red"><b>Bloco</b></td>
<td width="135px" style="color: red"><b>Ramal</b></td>
<td width="135px" style="color: red"><b>Setor</b></td>
<td width="135px" style="color: red"><b>Colaborador</b></td>
</tr>
<s:iterator value="select">
<tr>
<td><s:property value="bloco" /></td>
<td><s:property value="ramal" /></td>
<td><s:property value="setor" /></td>
<td><s:property value="colaborador" /></td>
</tr>
</s:iterator>
</table>
No browser dá o seguinte erro: “Error loading ‘select.action’ (500 Internal Server Error)”
Eu quero fazer uma pesquisa no banco e retornar em um List.
Não sei se estou passando os parâmetros de forma correta.
Eu ja consigo listar todos os dados do banco, e mostrar na tela!
assim:
public List<RamalBean> getRamais() {
this.session = MySQLDAOFactory.getSession();
List<RamalBean> listaRamal = this.session.createCriteria(
RamalBean.class).addOrder(Order.asc("setor").ignoreCase()).list();
this.session.close();
return listaRamal;
}
Consegui rodar sem erros assim:
public List<RamalBean> busca(RamalBean ramalBean) {
this.session = MySQLDAOFactory.getSession();
List<RamalBean> select = this.session.createCriteria(RamalBean.class).
add(Restrictions.like("setor", "%"+ramalBean.getSetor()+"%").ignoreCase()).list();
this.session.close();
return select;
}
Mas não está me retornando nada!
Se alguém tiver uma idéia do que pode ser, por favor poste.
Consegui, meu método de busca ficou assim:
public List<ListaBean> busca(ListaBean listaBean) {
this.session = MySQLDAOFactory.getSession();
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.like("colaborador",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("bloco",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("ramal",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("telefone",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("email",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("setor",
"%" + listaBean.getSetor() + "%").ignoreCase());
List<ListaBean> busca = this.session.createCriteria(ListaBean.class)
.addOrder(Order.asc("setor")).add(disjunction).list();
this.session.close();
return busca;
}
O SQL da consulta:
select
this_.id as id0_0_,
this_.bloco as bloco0_0_,
this_.colaborador as colabora3_0_0_,
this_.email as email0_0_,
this_.ramal as ramal0_0_,
this_.setor as setor0_0_,
this_.telefone as telefone0_0_
from
lista this_
where
(
lower(this_.colaborador) like ?
or lower(this_.bloco) like ?
or lower(this_.ramal) like ?
or lower(this_.telefone) like ?
or lower(this_.email) like ?
or lower(this_.setor) like ?
)
order by
this_.setor asc
Consegui, meu método de busca ficou assim:
public List<ListaBean> busca(ListaBean listaBean) {
this.session = MySQLDAOFactory.getSession();
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.like("colaborador",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("bloco",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("ramal",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("telefone",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("email",
"%" + listaBean.getSetor() + "%").ignoreCase());
disjunction.add(Restrictions.like("setor",
"%" + listaBean.getSetor() + "%").ignoreCase());
List<ListaBean> busca = this.session.createCriteria(ListaBean.class)
.addOrder(Order.asc("setor")).add(disjunction).list();
this.session.close();
return busca;
}
O SQL gerado:
select
this_.id as id0_0_,
this_.bloco as bloco0_0_,
this_.colaborador as colabora3_0_0_,
this_.email as email0_0_,
this_.ramal as ramal0_0_,
this_.setor as setor0_0_,
this_.telefone as telefone0_0_
from
lista this_
where
(
lower(this_.colaborador) like ?
or lower(this_.bloco) like ?
or lower(this_.ramal) like ?
or lower(this_.telefone) like ?
or lower(this_.email) like ?
or lower(this_.setor) like ?
)
order by
this_.setor asc