LeonardoCComp 28 de abr. de 2006
Obrigado Lipe.
Aproveitando o tópico, se um dos campos é String e o outro é Integer eu devo fazer o Cast na classe que dos contem o filtro ou na DAO onde está o Critéria?
Desculpem se não tiver sido claro nesta pergunta.
Mais uma vez obrigado!
LeonardoCComp 28 de abr. de 2006
Vou postar a classe toda mas só alterei os filtros…
Eu fiz assim:
FiltroPrincipal
public class FiltroPrincipal extends AbstractViewFilter {
private String infoPesquisa ;
private String telefoneCliente1 ;
private String idCliente ;
private String nomeCliente ;
public FiltroPrincipal buildView ( LogicDAO logicDAO , Locale locale )
throws Exception {
StringBuffer filter = new StringBuffer ();
StringBuffer footer = new StringBuffer ();
if ( infoPesquisa != null && infoPesquisa . trim (). length () > 0 ) {
filter . append ( infoPesquisa + " - " );
footer . append ( "filter_infoPesquisa=" + infoPesquisa . replaceAll ( " " , "%" ) + "&" );
}
if ( telefoneCliente1 != null && telefoneCliente1 . trim (). length () > 0 ) {
filter . append ( telefoneCliente1 + " - " );
footer . append ( "filter_telefoneCliente1=" + telefoneCliente1 . replaceAll ( " " , "%" ) + "&" );
}
if ( idCliente != null && telefoneCliente1 . trim (). length () > 0 ) {
filter . append ( Integer . parseInt ( idCliente ) + " - " );
footer . append ( "filter_idCliente=" + Integer . parseInt ( idCliente ) + "&" );
}
if ( nomeCliente != null && nomeCliente . trim (). length () > 0 ) {
filter . append ( nomeCliente + " - " );
footer . append ( "filter_nomeCliente=" + nomeCliente . replaceAll ( " " , "%" ) + "&" );
}
if ( filter . length () == 0 ) {
filter . append ( "Padrão" );
} else {
filter . delete ( filter . length () - 3 , filter . length () - 1 );
}
this . setLastFilter ( filter . toString ());
this . setFooter ( footer . toString ());
this . setPageTemplate ( "../filter/filtro_principal.jsp" );
return this ;
}
public String getNomeCliente () {
return nomeCliente ;
}
public void setNomeCliente ( String nomeCliente ) {
this . nomeCliente = nomeCliente ;
}
public String getInfoPesquisa () {
return infoPesquisa ;
}
public void setInfoPesquisa ( String infoPesquisa ) {
this . infoPesquisa = infoPesquisa ;
}
public String getIdCliente () {
return idCliente ;
}
public String getTelefoneCliente1 () {
return telefoneCliente1 ;
}
public void setIdCliente ( Integer idCliente ) {
this . idCliente = Integer . toString ( idCliente );
}
public void setTelefoneCliente1 ( String telefoneCliente1 ) {
this . telefoneCliente1 = telefoneCliente1 ;
}
}
No DAO está assim:
if ( filter .getInfoPesquisa () != null
&& filter .getInfoPesquisa () .trim () .length () > 0 ) {
criteria .add ( Expression .or (
Expression .like ( "Cliente.idCliente" ,
filter .getIdCliente ()) ,
Expression .like ( "Cliente.telefoneCliente1" ,
filter .getTelefoneCliente1 () .replaceAll ( " " , "%" ) + "%" ))) ;
}
if ( filter .getNomeCliente () != null
&& filter .getNomeCliente () .trim () .length () > 0 ) {
criteria .add ( Expression .like ( "Cliente.nome" , "%"
+ filter .getNomeCliente () .replaceAll ( " " , "%" ) + "%" )) ;
}
E apareceu isso aqui:
javax.servlet.ServletException: java.lang.NullPointerException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:516)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:423)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Estou errando onde?