Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Dear Rodrigo I tired your tip, but my response is: {json:[{value:Paddyfield Warbler,label:Paddyfield Warbler,id:Acrocephalus agricola}]} and -of course- there is no any suggest. :( I thought that Catalyst::View::JSON translate perl datastructures to corresponding JSON data structure ( hash object ... as i see on http://www.json.org) automatically. ( if not, i could use manually created JSON formatted string without any JSON module) Thank You! Have you tried this? sub request : Local { my ($self,$c) = @_; $c-stash-{json} = [ { id=Acrocephalus agricola, label= Paddyfield Warbler, value= Paddyfield Warbler } ]; $c-forward('View::JSON'); } It gives me back the following response: $ curl http://localhost:3000/request http://localhost:3000/test [{value:Paddyfield Warbler,id:Acrocephalus agricola,label:Paddyfield Warbler}] Which works with JQuery's autocomplete example just fine -rodrigo ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Looks like you need to set expose_stash = 'json' in your config. Hetényi Csaba wrote: Dear Rodrigo I tired your tip, but my response is: {json:[{value:Paddyfield Warbler,label:Paddyfield Warbler,id:Acrocephalus agricola}]} and -of course- there is no any suggest. :( I thought that Catalyst::View::JSON translate perl datastructures to corresponding JSON data structure ( hash object ... as i see on http://www.json.org) automatically. ( if not, i could use manually created JSON formatted string without any JSON module) Thank You! Have you tried this? sub request : Local { my ($self,$c) = @_; $c-stash-{json} = [ { id=Acrocephalus agricola, label= Paddyfield Warbler, value= Paddyfield Warbler } ]; $c-forward('View::JSON'); } It gives me back the following response: $ curl http://localhost:3000/request http://localhost:3000/test [{value:Paddyfield Warbler,id:Acrocephalus agricola,label:Paddyfield Warbler}] Which works with JQuery's autocomplete example just fine -rodrigo ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Dear Ben van Staveren Thank You, now it is working, but in this case, i don't know why to use Catalyst::View::JSON, it is just a text formatting. Later I'd like to use DBIx datasource to feed autocomplete plugin, in this case i must manually build a special JSON formatted string. Is there exist a better way? Thank You! Ben van Staveren írta: Looks like you need to set expose_stash = 'json' in your config. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Ahh! That was the trick :))) (expose_stash = 'json') Now it is correctly translate the perl arrayref datastructure to JSON array ( [ ... ] ) my @aoh = ( { value = 1, label = betty, }, { value = 2, label= jane, }, { value = 3, label= marge, }, ); $c-stash-{json} = \...@aoh; $c-forward('View::JSON'); :) Thanks Ben! One last question: if I have a DBIx resultset, how to use it to populate autocomplete with the easiest way? Best wishes from Hungary! Ben van Staveren írta: You can do that with View::JSON :) Just read the docs though, the reason it didn't work is that you put your data in $c-stash-{json} = [ ... ] And View::JSON will attempt to turn your entire stash into JSON data :) And it does that bit correctly, but the thing you end up with is { json: [ ... ] } And autocomplete doesn't like that. So, either do: $c-stash([ ... ]) Or set the expose_stash setting. Whatever is set in there, is the only thing that View::JSON will attempt to serialise. Personally I prefer expose_stash = 'json', so that anything under $c-stash-{json} is serialised, but up to you :) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Probably not the most pretty one but: Given you have a resultset obtained with, say, my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...}); $c-stash-{json} = [ map { id = $_-id, label = $_-name } ($result_set-all) ]; Or a bit more verbose: foreach my $result ($result_set-all) { push(@{$c-stash-{json}}, { id = $result-id, label = $result-name }); } ` Hetényi Csaba wrote: Ahh! That was the trick :))) (expose_stash = 'json') Now it is correctly translate the perl arrayref datastructure to JSON array ( [ ... ] ) my @aoh = ( { value = 1, label = betty, }, { value = 2, label= jane, }, { value = 3, label= marge, }, ); $c-stash-{json} = \...@aoh; $c-forward('View::JSON'); :) Thanks Ben! One last question: if I have a DBIx resultset, how to use it to populate autocomplete with the easiest way? Best wishes from Hungary! Ben van Staveren írta: You can do that with View::JSON :) Just read the docs though, the reason it didn't work is that you put your data in $c-stash-{json} = [ ... ] And View::JSON will attempt to turn your entire stash into JSON data :) And it does that bit correctly, but the thing you end up with is { json: [ ... ] } And autocomplete doesn't like that. So, either do: $c-stash([ ... ]) Or set the expose_stash setting. Whatever is set in there, is the only thing that View::JSON will attempt to serialise. Personally I prefer expose_stash = 'json', so that anything under $c-stash-{json} is serialised, but up to you :) ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
On Mon, 26 Apr 2010 16:33:31 +0700 Ben van Staveren benvanstave...@gmail.com wrote: Probably not the most pretty one but: Given you have a resultset obtained with, say, my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...}); $c-stash-{json} = [ map { id = $_-id, label = $_-name } ($result_set-all) ]; Or a bit more verbose: foreach my $result ($result_set-all) { push(@{$c-stash-{json}}, { id = $result-id, label = $result-name }); } ` I've also had good luck using DBIx::Class::RsultClass::HashRefInflator in the past. It doesn't give you quite as much control, but it may be enough for your needs. http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRefInflator.pm -- Lee Aylward ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Used it but at the same time, doing my $hashref = { $row-get_columns } got me more or less the same effect for a lot less hassle :) I actually do this for most my DB objects that get serialised to JSON, quite simple case of $c-stash-{json} = [ map { $_-get_columns } $rs-all ]; In a similar vein, I haven't yet really seen/heard any sort of best practices when it comes to Catalyst and JSON, so maybe I'm going about it all wrong but eh :) Lee Aylward wrote: On Mon, 26 Apr 2010 16:33:31 +0700 Ben van Staveren benvanstave...@gmail.com wrote: Probably not the most pretty one but: Given you have a resultset obtained with, say, my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...}); $c-stash-{json} = [ map { id = $_-id, label = $_-name } ($result_set-all) ]; Or a bit more verbose: foreach my $result ($result_set-all) { push(@{$c-stash-{json}}, { id = $result-id, label = $result-name }); } ` I've also had good luck using DBIx::Class::RsultClass::HashRefInflator in the past. It doesn't give you quite as much control, but it may be enough for your needs. http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRefInflator.pm -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
HRI will return prefetched rels too, get_columns won't. -- Best regards, Alex Am Montag, den 26.04.2010, 17:23 +0200 schrieb Ben van Staveren: Used it but at the same time, doing my $hashref = { $row-get_columns } got me more or less the same effect for a lot less hassle :) I actually do this for most my DB objects that get serialised to JSON, quite simple case of $c-stash-{json} = [ map { $_-get_columns } $rs-all ]; In a similar vein, I haven't yet really seen/heard any sort of best practices when it comes to Catalyst and JSON, so maybe I'm going about it all wrong but eh :) Lee Aylward wrote: On Mon, 26 Apr 2010 16:33:31 +0700 Ben van Staveren benvanstave...@gmail.com wrote: Probably not the most pretty one but: Given you have a resultset obtained with, say, my $result_set = $c-model('DB::Somedata')-search_rs({...}, {...}); $c-stash-{json} = [ map { id = $_-id, label = $_-name } ($result_set-all) ]; Or a bit more verbose: foreach my $result ($result_set-all) { push(@{$c-stash-{json}}, { id = $result-id, label = $result-name }); } ` I've also had good luck using DBIx::Class::RsultClass::HashRefInflator in the past. It doesn't give you quite as much control, but it may be enough for your needs. http://search.cpan.org/~frew/DBIx-Class/lib/DBIx/Class/ResultClass/HashRefInflator.pm -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com *** T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien Handelsgericht Wien, FN 79340b *** Notice: This e-mail contains information that is confidential and may be privileged. If you are not the intended recipient, please notify the sender and then delete this e-mail immediately. *** ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
Dear All Is there anyone, who has success with this combination? I have no idea, how to use this. On the Jquery Autocomplete demo page, i 'd like to do as you can see in the second demo (Remote datasource), but not working. If examine the original demo response with firebug, i see, that the 'search.php' (which is used in the demo as a remote datasource) response is HTML header and NOT JSON, and it is working. If i changed to my own response generated with C:W:JSON, i see the correct type: JSON, but there is no suggestion appears. I noticed, the Autocomplete plugin waits for String-Array or Object-Array, (which starts and ends with [ ...] ) but my code always starts and ends with { ... } (JSON object type). I tried many perl data-structure, but always starts with { ... Original working response (with HTML header): |[ { id: Acrocephalus agricola, label: Paddyfield Warbler, value: Paddyfield Warbler } ] My not woking response with JSON header: ||{value:Common Shelduck,id:Tadorna tadorna,label:Common Shelduck}| Thank you in advance!! ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using Jquery UI Autocomplete widget with Catalyst::View::JSON
I noticed, the Autocomplete plugin waits for String-Array or Object-Array, (which starts and ends with [ ...] ) but my code always starts and ends with { ... } (JSON object type). I tried many perl data-structure, but always starts with { ... Original working response (with HTML header): [ { id: Acrocephalus agricola, label: Paddyfield Warbler, value: Paddyfield Warbler } ] My not woking response with JSON header: {value:Common Shelduck,id:Tadorna tadorna,label:Common Shelduck} Have you tried this? sub request : Local { my ($self,$c) = @_; $c-stash-{json} = [ { id=Acrocephalus agricola, label= Paddyfield Warbler, value= Paddyfield Warbler } ]; $c-forward('View::JSON'); } It gives me back the following response: $ curl http://localhost:3000/request http://localhost:3000/test [{value:Paddyfield Warbler,id:Acrocephalus agricola,label:Paddyfield Warbler}] Which works with JQuery's autocomplete example just fine -rodrigo ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/