erro autocomplete jquery-1.11.1.js?compile=false:9176
Closed this issue · 32 comments
Good afternoon I'm trying to use the autocomplete and shows me the following error:
GET http://localhost:8089/bioweb/autoComplete/autocomplete?domain=bioweb.centro_custo&searchField=descricao&max=10&order=asc&collectField=id&term=i 403 (Forbidden) jQuery.ajaxTransport.send @ jquery-1.11.1.js compile = false: 9631jQuery.extend.ajax @ jquery-1.11.1.js compile = false: 9176e.widget._initSource.e.isArray. string.options.source.source @ jquery-ui.min.js compile = false: 7e.widget._search @ jquery-ui.min.js compile = false: 7 (anonymous function) @ jquery-ui.min. ? js compile = false: 6e.widget.search @ jquery-ui.min.js compile = false:? 7 (anonymous function) @ jquery-ui.min.js compile = false: 6 (anonymous function) @ jquery- ? ui.min.js compile = false: 7i @ jquery-ui.min.js compile = false: 6
Follows the way of how I'm using:
<Label> CentroCustos: </ label>
<G: autocomplete
id = "primarySearch"
controller = ""
action = ""
name = "centrocustos_id"
domain = 'bioweb.centro_custo'
searchField = 'description'
collectField = 'id'
value = "$ {params.myId}"
max = "10"
order = "asc"
required = "false"
/>
Hi Biosystem,
You would need to add this to your call in order to load the local jquery-ui:
loadjui='enable'
Other than that you would need to provide your own jquery and jquery-ui
Can you please confirm the configuration / version of both as well as what grails version you are using
I will then setup the same setup and try to find a fix. I suspect the version of jquery-ui possibly in the plugin is the issue.
Hello I'm using grail 2.5
thanks and you are using jquery-ui as well ? If so what version. Also have you tried adding
loadjui='enable'
to your g:autocomeplete call to see if it changes anything ? you should only need to call it once per any amount of call on any page.
Or simply add
<g:loadjui />
above the g:autoComplete call you are making to see if it makes any difference
Please refer to my previous comment, I have just downloaded grails 2.5.0 and setup a demo site that appears to be working with auto complete:
https://github.com/vahidhedayati/testads5/blob/master/grails-app/views/layouts/main.gsp#L20
<g:loadjui />
This has been added to my main layout which loads in jquery-ui into my app and is loaded on each page that loads in the main layout.
You could set this up on the gsp page that is making the actual g:autocomplete call.
In order for autoComplete to work it relies on jquery-ui, grails by default does not provide you with this and you could set up jquery-ui in grails by adding the plugin and configuration required. Or simple load it in as you see
I tested this from that demo site:
https://github.com/vahidhedayati/testads5/blob/master/grails-app/views/myContinent/example.gsp#L242
and it appeared to work fine, I loaded up the site and clicked on variety ..
git clone https://github.com/vahidhedayati/testads5.git
cd testads5
grails run-app
vahidhedayati
Hand me I skype to talk . or hangout
you can reach me on hangouts : https://github.com/vahidhedayati/ajaxdependancyselection/blob/grails2/AjaxdependancyselectionGrailsPlugin.groovy#L10
But I won't be able to help you until after 5:30 pm BST(today) since I am at work
Ok sorry been busy and I should have updated your answers to get a better idea of what you were actually defining in the call:
<label>CentroCustos:</label>
<g:loadjui/>
<g:autocomplete
id="primarySearch"
name="centrocustos_id"
domain='bioweb.centro_custo'
searchField='descricao'
collectField='id'
value="${params.myId}"
max="10"
order="asc"
required="false"
/>
Try above, you had defined:
controller = "contasPagar"
action = ""
This maybe the cause of your issue, since by declaring this, typically you are telling the plugin that you prefer to take over the process of producing the JSON result that is fed back to the taglib call...
If you now look at your screen shot, the last 404 the actual URL:
http://localhost:8089/bioweb/contasPagar/autoComplete?.... 404
So you have told the plugin to access, no Action default being:
To access it on the defined controller name:
http://localhost:8089/bioweb/contasPagar/autoComplete this won't exist on your project and hence will make the actual call fail.
Please remove controller and action to fix this issue.
Okay,
The error may be in jquery for several js use in my project.
He is automatically placing the URL.
Enter hongouts?
GET http://localhost:8089/bioweb/autoComplete/autocomplete?domain=bioweb.centro_custo&searchField=descricao&max=10&order=asc&collectField=id&term=INF 403 (Forbidden)jQuery.ajaxTransport.send @ jquery-1.11.1.js?compile=false:9631jQuery.extend.ajax @ jquery-1.11.1.js?compile=false:9176e.widget._initSource.e.isArray.string.options.source.source @ jquery-ui.min.js?compile=false:7e.widget._search @ jquery-ui.min.js?compile=false:7(anonymous function) @ jquery-ui.min.js?compile=false:6e.widget.search @ jquery-ui.min.js?compile=false:7(anonymous function) @ jquery-ui.min.js?compile=false:6(anonymous function) @ jquery-ui.min.js?compile=false:7i @ jquery-ui.min.js?compile=false:6
Hi sorry for not responding earlier I think we're in different time zones.
The new problem is 403 forbidden
Sounds like you got some forms of security enabled that is stopping the url from being accessible
Take a look at https://stackoverflow.com/questions/20026279/i-want-my-selects-dropdowns-to-auto-populate-with-ajax-in-grails-website
If you read the comments. This user also had same issue until security changes in their app.
Regards
Error |
2015-05-28 11:20:24,813 [http-bio-8089-exec-8] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /bioweb/autoComplete/autocomplete - parameters:
collectField: id
max: 10
order: asc
term: INF
domain: bioweb.centro_custo
searchField: descricao
Cannot get property 'clazz' on null object. Stacktrace follows:
Message: Cannot get property 'clazz' on null object
Line | Method
->> 44 | autocompletePrimaryAction in grails.plugin.ajaxdependancyselection.AutoCompleteService
| 23 | autocomplete in grails.plugin.ajaxdependancyselection.AutoCompleteController
| 198 | doFilter . . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 53 | doFilter . . . . . . . . in grails.plugin.multitenant.core.servlet.CurrentTenantServletFilter
| 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
| 82 | doFilter . . . . . . . . in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 724 | run in java.lang.Thread
def domainClass = grailsApplication.getDomainClass(domain).clazz
domain: bioweb.centro_custo
searchField: descricao
This is definitely your domainClass and its package convention ?
I mean I have never created any domain classes with underscores..
Can you please post that domainClass contents
using this key 3 times all together before pasting and after the code block :
`
package bioweb
class centroCusto{
String descricao
}
If your package name is exactly as it is and if the class is centroCusto as I have done then your domain should be:
domain: bioweb.centroCusto
searchField: descricao
This is not a database query so you would not to change appName to app_name, it requires actual object to query
Thank you friend,
It worked perfectly changed the class domain to CentroCusto . Now this one accusing the image of the error and already put it in the directory follows the error.
GET http : // localhost: 8089 / Bioweb / assets / images / ui- bg_highlight - soft_100_eeeeee_1x100.png 404 ( Not Found)
ui- bg_highlight - soft_100_eeeeee_1x100.png is part of jquery-ui, since you are loading up the jquery-ui from the plugin, I have taken a look and I am missing images.
Let me fix it test it and give you an update.
try the updated version 0.45
In the table contasPagar not this saving in centrocustos_id field below shows how I'm doing
Save the table contasPagar the field centrocustos_id
<label>CentroCustos:</label>
<g:loadjui/>
<g:autocomplete
id="primarySearch"
name="centrocustos_id"
domain='bioweb.CentroCusto'
searchField='descricao'
collectField='id'
value="${contasPagarInstance?.centrocustos?.descricao}"
max="10"
order="asc"
required="true"
/>
```gsp
Sorry as I update the version ?
version update. tank you
In the table contasPagar not this saving in centrocustos_id field below shows how I'm doing
Save the table contasPagar the field centrocustos_id
CentroCustos:
id="primarySearch"
name="centrocustos_id"
domain='bioweb.CentroCusto'
searchField='descricao'
collectField='id'
value="${contasPagarInstance?.centrocustos?.descricao}"
max="10"
order="asc"
required="true"
/>
I suggest you send your form result to a test page/controller that does either in controller:
println "${params}"
or in gsp
${params}
and view what is being sent to see what it is you are looking for and what you need it to be
I have no idea about your setup and unsure what
centrocustos_id
is meant to be if this is some relationship it should possible be
centrocustos.id
You can find this sort of information out by generating the CRUD i.e. generate-controller generate-view for the given domainClass
Then view the gsp fields defined and it may give you a better clue
the scaffold he generated as follows:
_form.gps
<g:message code="contasPagar.centrocustos.label" default="Centrocustos"/>
*
<g:select id="centrocustos" name="centrocustos.id" from="${bioweb.CentroCusto.list()}" optionKey="id" required=""
value="${contasPagarInstance?.centrocustos?.id}" class="many-to-one"/>
index.gsp:
<g:if test="${contasPagarInstance?.centrocustos}">
<g:message
code="contasPagar.centrocustos.label" default="Centrocustos"/>
<span class="property-value" aria-labelledby="centrocustos-label"><g:link
controller="centroCusto" action="show"
id="${contasPagarInstance?.centrocustos?.id}">${contasPagarInstance?.centrocustos?.encodeAsHTML()}</g:link></span>
</li>
</g:if>
its right there: centrocustos.id so you need to change the centrocustos_id to centrocustos.id and hopefully it will work.
I take it you are quite new to grails, although this is kind of unrelated:
https://github.com/vahidhedayati/testads5/blob/master/grails-app/conf/BootStrap.groovy
It gives you an idea of objects in your controller (if all that centrocustos?.id fails)
You could get the object Custos and save it as the object like you see in bootstrap
so
def myCustro = Custro.get(params.centrocustos_id) //if you leave it as it is.
def c1 = centroCusto.findOrSaveWhere(custos: myCustro, otherField: otherValue...)
where custos is what ever you have defined the relationship
static hasMany = [ Custos: custos]
and myCustro is the object that is picked up from your id.
Here is a really good example:
Visit createVisit(long petId, String description, Date date) {
def visit = new Visit(pet: Pet.load(petId), description: description, date: date)
visit.save()
visit
}
Where they load petId well they get the object and save it in the new call, usually though :
visit.save(flush:true)
If you are going to interact with that data immediately
I'm really new to Grails I 'm Delphi Developer
Example supplier saving correctly in table title fornecedor_id field
<g:message code="contasPagar.fornecedor.label" default="Fornecedor"/>
*
<g:select id="fornecedor" name="fornecedor.id" from="${bioweb.Fornecedor.list()}" optionKey="id" required=""
value="${contasPagarInstance?.fornecedor?.id}" class="many-to-one"/>
Example scaffold
<g:message code="contasPagar.centrocustos.label" default="Centrocustos"/>
*
<g:select id="centrocustos" name="centrocustos.id" from="${bioweb.CentroCusto.list()}" optionKey="id" required=""
value="${contasPagarInstance?.centrocustos?.id}" class="many-to-one"/>
Example ajaxdependency
<label>CentroCustos:</label>
<g:loadjui/>
<g:autocomplete
id="primarySearch"
name="centrocustos.id"
domain='bioweb.CentroCusto'
searchField='descricao'
collectField='id'
value="${contasPagarInstance?.centrocustos?.descricao}"
max="10"
order="asc"
required="true"
/>
and what is it doing to save.. can you provide what this autocomplete posts to, you should be able to use the above method and actually grab the centrocustos object bound to the id you are sending and save that way.
To finalise problem and solution:
<g:autoCompletePrimary id="primarySearch1"
name="NAMEOFcontinentName"
domain='ajaxdependancyselectexample.MyContinent'
searchField='continentName'
collectField='id'
hidden='hidden3'
value=''/>
<input type=hidden id="hidden3" name="continentId" value=""/>
A requirement to select value and save id best to use <g:autoCompletePrimary in grails2 and <ads:autoCompletePrimary in grails 3
You mean you want live working site, sure no problems you have the metal(server) and the internet :) otherwise just download the demo site and do run grails run-app on your local PC hehe.
I thought yours was working ? :)
The actual issue was bound to the code checked in to grails 3 branch so I added the above comments to finalise the issue, what was done as in the issues faced. With the comment being the final fix for this problem which was to use <g:selectPrimary and have a hidden field to store the autocomplete selection.
Will close this issue - I think it is now resolved :)