Filtros interdependentes
26/08/2014 19:59
0
Boa noite,

Preciso que na index user gerada pelo Spring Security-core, possibilite uma busca com ajax para que se torne dinâmico através de filtros interdependentes, alguém saberia como fazer se estou seguindo o caminho certo? O código está abaixo:

def search = {

def list

if (params.username && params.enable)
list = User.findAllByUsernameIlikeAndenableIlike(wrapSearchParm(params.username), wrapSearchParm(params.enable))
else if (params.username)
list = Book.findAllByUsernameIlike(wrapSearchParm(params.username))
else if (params.enable)
list = Book.findAllByTitleIlike(wrapSearchParm(params.title))

render(template:'searchResults', model:[searchresults:list])

}

a classe possui os atributos abaixo, só que se for seguir desse modo acima o código ficará um pouco extenso, se puderem me ajudar agradeço...

String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
Tags: filters, ajax, busca, dinâmico


1
Use criteria.

def usuarios = User.createCriteria().list(){
if (params.username){
ilike('username', params.username)
}
if (params.password){
eq('password', params.password)
}

// e por ai vai.
order('username', 'asc')
}
26/08/2014 23:10


0
Obrigado Carlos,

vou tentar aqui...
27/08/2014 10:29


0
Boa noite,

realizado conforme explicado pelo Carlos, está retornando o erro abaixo. alguém pode ajudar?




Around line 30 of grails-app\controllers\panel\UserController.groovy
27: }
28:
29: def search = User.createCriteria().list(){
30: if (params.username){
31: ilike('username', params.username)
32: }
33: if (params.enable){
Around line 29 of grails-app\controllers\panel\UserController.groovy
26:
27: }
28:
29: def search = User.createCriteria().list(){
30: if (params.username){
31: ilike('username', params.username)
32: }
27/08/2014 19:31


0
Coloque o erro todo.
27/08/2014 22:01


0
Boa noite,

Segue erro completo

URI
/Panel/user/index
Class
java.lang.NullPointerException
Message
null
Around line 116 of AbstractFilter.java
113: throw (IOException)throwable;
114: }
115:
116: throw new ServletException(throwable);
117: }
118:
119: protected CacheManager getCacheManager() {
Around line 70 of AbstractFilter.java
67: }
68: }
69: catch (Throwable throwable) {
70: logThrowable(throwable, request);
71: }
72: }
73:
Around line 53 of GrailsAnonymousAuthenticationFilter.java
50:
51: applyAnonymousForThisRequest((HttpServletRequest)req);
52:
53: chain.doFilter(req, res);
54: }
55:
56: protected void applyAnonymousForThisRequest(HttpServletRequest request) {
Around line 49 of RequestHolderAuthenticationFilter.java
46: public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
47: SecurityRequestHolder.set((HttpServletRequest)request, (HttpServletResponse)response);
48: try {
49: super.doFilter(request, response, chain);
50: }
51: finally {
52: SecurityRequestHolder.reset();
Around line 82 of MutableLogoutFilter.java
79: return;
80: }
81:
82: chain.doFilter(request, response);
83: }
84:
85: /**
Around line 196 of AbstractFilter.java
193: protected <T> T getBean(String name) {
194: ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(
195: getServletContext());
196: return (T)ctx.getBean(name);
197: }
198:
199: /**
Around line 851 of PageFragmentCachingFilter.java
848: if (controllerClass == null) {
849: return null;
850: }
851: return getBean(controllerClass.getName());
852: }
853:
854: /**
Around line 175 of PageFragmentCachingFilter.java
172:
173: try {
174:
175: Object controller = lookupController(getContext().getControllerClass());
176: if (controller == null) {
177: log.debug("Not a controller request {}:{} {}",
178: new Object[] { request.getMethod(), request.getRequestURI(), getContext() });
Around line 63 of AbstractFilter.java
60: try {
61: // NO_FILTER set for RequestDispatcher forwards to avoid double gzipping
62: if (filterNotDisabled(request)) {
63: doFilter(request, response, chain);
64: }
65: else {
66: chain.doFilter(req, res);
Around line 30 of grails-app\controllers\panel\UserController.groovy
27: }
28:
29: def search = User.createCriteria().list(){
30: if (params.username){
31: ilike('username', params.username)
32: }
33: if (params.enable){
Around line 29 of grails-app\controllers\panel\UserController.groovy
26:
27: }
28:
29: def search = User.createCriteria().list(){
30: if (params.username){
31: ilike('username', params.username)
32: }
Trace
Line | Method
->> 116 | logThrowable in AbstractFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 70 | doFilter in ''
| 53 | doFilter . . in GrailsAnonymousAuthenticationFilter.java
| 49 | doFilter in RequestHolderAuthenticationFilter.java
| 82 | doFilter . . in MutableLogoutFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

Caused by BeanCreationException: Error creating bean with name 'panel.UserController': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [panel.UserController]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 196 | getBean in AbstractFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 851 | lookupController in PageFragmentCachingFilter.java
| 175 | doFilter . . in ''
| 63 | doFilter in AbstractFilter.java
| 53 | doFilter . . in GrailsAnonymousAuthenticationFilter.java
| 49 | doFilter in RequestHolderAuthenticationFilter.java
| 82 | doFilter . . in MutableLogoutFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

Caused by BeanInstantiationException: Could not instantiate bean class [panel.UserController]: Constructor threw exception; nested exception is java.lang.NullPointerException
->> 196 | getBean in AbstractFilter.java
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 851 | lookupController in PageFragmentCachingFilter.java
| 175 | doFilter . . in ''
| 63 | doFilter in AbstractFilter.java
| 53 | doFilter . . in GrailsAnonymousAuthenticationFilter.java
| 49 | doFilter in RequestHolderAuthenticationFilter.java
| 82 | doFilter . . in MutableLogoutFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

Caused by NullPointerException: null
->> 30 | doCall in UserController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 1854 | invokeClosureNode in grails.orm.HibernateCriteriaBuilder
| 1553 | invokeMethod in ''
| 29 | ___init___ in UserController.groovy
| 196 | getBean . . in AbstractFilter.java
| 851 | lookupController in PageFragmentCachingFilter.java
| 175 | doFilter . . in ''
| 63 | doFilter in AbstractFilter.java
| 53 | doFilter . . in GrailsAnonymousAuthenticationFilter.java
| 49 | doFilter in RequestHolderAuthenticationFilter.java
| 82 | doFilter . . in MutableLogoutFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread
Terms of Service
Privacy P
28/08/2014 19:15



Ainda não faz parte da comunidade???

Para se registrar, clique aqui.


Aprenda Groovy e Grails com a Formação itexto!

Newsletter Semana Groovy

Assinar

Envie seu link!


Livro de Grails


/dev/All

Os melhores blogs de TI (e em português) em um único lugar!

 
Creative Commons
RSS Grails Brasil é mantido por itexto Consultoria.
Em caso de problemas contacte Henrique Lobo Weissmann (Kico) por e-mail: kico@itexto.com.br
Todo o conteúdo presente neste site adota o Creative Commons como licença padrão.
Ver: 4.14.0
itexto