FAQ
Thanks for the help! It seems very obvious in retrospect. I guess I was just
expecting a to get warns instead of errors. It's working well now. Thanks
again.

Now on to the next problem:

I'm trying to load a jqGrid from json data made via a REST call. But my grid
is just a blank rectangle on the page. Here is my code:

<body>

<div id="tabs">
<ul>
<li><a href="#panel-users">Users</a></li>
<li><a href="#panel-clients">Clients</a></li>

</ul>
<div id="panel-users">
<table id="list"></table>
<div id="pager"></div>
</div>
<div id="panel-clients">

</div>
</div>

<script type="text/javascript">
$(function() {
$("#tabs").tabs();
});
</script>

<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#list").jqGrid({
url:'http://192.168.20.155:3000/admin/rest/users',
dataType: 'json',
mtype: 'GET',
colNames:['Id','Username',
'Minutes','Status','Message','Notes','Troublemaker'],
colModel :[
{name:'id', index:'id', width:11},
{name:'username', index:'username', width:90},
{name:'minutes', index:'minutes', width:3, align:'right'},
{name:'status', index:'status', width:80, align:'right'},
{name:'message', index:'message', width:80, align:'right',
sortable:false},
{name:'note', index:'note', width:150, sortable:false},
{name:"troublemaker", index:'troublemaker', width:1}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'username',
sortorder: 'desc',
viewrecords: true,
caption: 'My test grid',
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: true,
cell: "cell",
id: "id",
userdata: "userdata"
}
});
});
</script>


And here is the JSON data that the url returns:

{"page":0,"records":"3","total":1,"rows":[{"cell":["1","admin","30","enabled",null,null,"0"]},{"cell":["2","test1","30","enabled",null,null,"0"]},{"cell":["3","test2","30","enabled",null,null,"0"]}]}

I know this isn't specifically a Catalyst question, but I thought someone
here may have experienced this before. I'm using Controller::REST and
Catalyst::TraitFor::Controller::jQuery::jqGrid. Any help would be greatly
appreciated.
Here is the REST controller for posterity:
package LibkiServer::Controller::Admin::REST;
use Moose;
use namespace::autoclean;

with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

BEGIN {extends 'Catalyst::Controller::REST'; }

=head1 NAME

LibkiServer::Controller::Admin::REST - Catalyst REST Controller

=head1 DESCRIPTION

Catalyst REST Controller for Administration.

=head1 METHODS

=cut


=head2 index

=cut

sub users : Local : ActionClass('REST') { }

sub users_GET {
my ( $self, $c ) = @_;

my $user_rs = $c->model('DB::User')->search( {}, { prefetch => { session
=> 'client' } } );
$user_rs = $self->jqgrid_page( $c, $user_rs );

my $row = 0;
my @row_data;

while ( my $user = $user_rs->next() ) {
my $user_id = $user->id;

my @cell;
push( @cell, $user->id );
push( @cell, $user->username );
push( @cell, $user->minutes );
push( @cell, $user->status );
push( @cell, $user->message );
push( @cell, $user->notes );
push( @cell, $user->is_troublemaker );
push( @cell, defined( $user->session ) ? $user->session->status :
undef );
push( @cell, defined( $user->session ) ? $user->session->client->id
: undef );
push( @cell, defined( $user->session ) ?
$user->session->client->clientname : undef );
my $single_row = {
cell => \@cell
};
push( @row_data, $single_row );

}

$self->status_ok(
$c,
entity => {
page => $c->stash->{json_data}->{page},
total => $c->stash->{json_data}->{total},
records => $c->stash->{json_data}->{records},
rows => \@row_data
}
);
}


http://www.kylehall.info
Mill Run Technology Solutions ( http://millruntech.com )
Crawford County Federated Library System ( http://www.ccfls.org )
Meadville Public Library ( http://www.meadvillelibrary.org )


On Thu, Jul 8, 2010 at 12:02 PM, Jeff Albert wrote:

Some of your users have sessions, and thus will have a row or rows in the
related �session� resultset � but some don�t. When you attempt to access
$user->session->client->clientname, you�re assuming that $user->session is
defined � but in the case of a user row with no related session row,
$user->session won�t be defined, and you�ll raise the error you described
when you attempt to access the methods of that resultset. Do a quick
defined() test on $user->session before you try to use its methods, and
you�ll be good to go. Hope that helps!



Cheers,

Jeff Albert



*From:* Kyle Hall
*Sent:* Thursday, July 08, 2010 7:57 AM
*To:* catalyst@lists.scsys.co.uk
*Subject:* [Catalyst] Nonsensical Problem with DBIx ResultSet



Hello all,
I'm the developer of a FOSS kiosk management system, Libki. I'm in the
early stages of a complete rewrite using Catalyst for the web-based
administration interface. This is my first time using Catalyst, but I'm very
excited by the possibilities! I'm having a very strange issue with my
resultsets. For example, I have three tables, a users table, a clients
table, and a sessions table that connects the user to a client.

I grab my users from the database, with any session/client data if the user
is currently logged in to a client kiosk. I am prefetching the session and
client table data.

my $user_rs = $c->model('DB::User')->search( {}, { prefetch => { session =>
'client' } } );

Now I want to loop through it.

my $row = 0;
my @row_data;

while ( my $user = $user_rs->next() ) {
my $user_id = $user->id;

warn $user->session->client->clientname;

my $single_row = {
cell => [
$user->id,
$user->username,
$user->minutes,
$user->status,
$user->is_troublemaker,
$user->session->client->clientname;
]
};
push( @row_data, $single_row );
}


Now, if I try to access any of the other tables, I get an error:
[error] Caught exception in LibkiServer::Controller::Admin::REST->users
"Can't call method "client" on an undefined value at
/home/libki/LibkiServer/script/../lib/LibkiServer/Controller/Admin/REST.pm
line 40."

I don't know why I get this error, but the really crazy part is *the warn
still works*:
Client Name: testclient1 at
/home/libki/LibkiServer/script/../lib/LibkiServer/Controller/Admin/REST.pm
line 40.

If anyone can help me out, I'd be eternally grateful.

Thanks,
Kyle

http://www.kylehall.info
Mill Run Technology Solutions ( http://millruntech.com )
Crawford County Federated Library System ( http://www.ccfls.org )
Meadville Public Library ( http://www.meadvillelibrary.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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100708/9122aff5/attachment.htm

Search Discussions

  • Kyle Hall at Jul 8, 2010 at 5:45 pm
    I figured it out. I simply had to include grid.locale-en.js *before*
    jquery.jqGrid.min.js. Again, thanks for the help.

    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )


    On Thu, Jul 8, 2010 at 1:08 PM, Kyle Hall wrote:

    Thanks for the help! It seems very obvious in retrospect. I guess I was
    just expecting a to get warns instead of errors. It's working well now.
    Thanks again.

    Now on to the next problem:

    I'm trying to load a jqGrid from json data made via a REST call. But my
    grid is just a blank rectangle on the page. Here is my code:

    <body>

    <div id="tabs">

    <ul>
    <li><a href="#panel-users">Users</a></li>

    <li><a href="#panel-clients">Clients</a></li>

    </ul>
    <div id="panel-users">

    <table id="list"></table>

    <div id="pager"></div>

    </div>
    <div id="panel-clients">

    </div>
    </div>

    <script type="text/javascript">

    $(function() {
    $("#tabs").tabs();

    });
    </script>

    <script type="text/javascript">

    jQuery(document).ready(function(){

    jQuery("#list").jqGrid({
    url:'http://192.168.20.155:3000/admin/rest/users',

    dataType: 'json',
    mtype: 'GET',

    colNames:['Id','Username', 'Minutes','Status','Message','Notes','Troublemaker'],

    colModel :[
    {name:'id', index:'id', width:11},

    {name:'username', index:'username', width:90},

    {name:'minutes', index:'minutes', width:3, align:'right'},

    {name:'status', index:'status', width:80, align:'right'},

    {name:'message', index:'message', width:80, align:'right', sortable:false},

    {name:'note', index:'note', width:150, sortable:false},

    {name:"troublemaker", index:'troublemaker', width:1}

    ],
    pager: '#pager',
    rowNum:10,

    rowList:[10,20,30],

    sortname: 'username',
    sortorder: 'desc',

    viewrecords: true,
    caption: 'My test grid',

    jsonReader : {
    root: "rows",

    page: "page",
    total: "total",

    records: "records",
    repeatitems: true,

    cell: "cell",
    id: "id",

    userdata: "userdata"
    }
    });
    });
    </script>


    And here is the JSON data that the url returns:


    {"page":0,"records":"3","total":1,"rows":[{"cell":["1","admin","30","enabled",null,null,"0"]},{"cell":["2","test1","30","enabled",null,null,"0"]},{"cell":["3","test2","30","enabled",null,null,"0"]}]}

    I know this isn't specifically a Catalyst question, but I thought someone
    here may have experienced this before. I'm using Controller::REST and
    Catalyst::TraitFor::Controller::jQuery::jqGrid. Any help would be greatly
    appreciated.
    Here is the REST controller for posterity:
    package LibkiServer::Controller::Admin::REST;
    use Moose;
    use namespace::autoclean;

    with 'Catalyst::TraitFor::Controller::jQuery::jqGrid';

    BEGIN {extends 'Catalyst::Controller::REST'; }

    =head1 NAME

    LibkiServer::Controller::Admin::REST - Catalyst REST Controller

    =head1 DESCRIPTION

    Catalyst REST Controller for Administration.

    =head1 METHODS

    =cut


    =head2 index

    =cut

    sub users : Local : ActionClass('REST') { }

    sub users_GET {
    my ( $self, $c ) = @_;

    my $user_rs = $c->model('DB::User')->search( {}, { prefetch => {
    session => 'client' } } );
    $user_rs = $self->jqgrid_page( $c, $user_rs );

    my $row = 0;
    my @row_data;

    while ( my $user = $user_rs->next() ) {
    my $user_id = $user->id;

    my @cell;
    push( @cell, $user->id );
    push( @cell, $user->username );
    push( @cell, $user->minutes );
    push( @cell, $user->status );
    push( @cell, $user->message );
    push( @cell, $user->notes );
    push( @cell, $user->is_troublemaker );
    push( @cell, defined( $user->session ) ? $user->session->status :
    undef );
    push( @cell, defined( $user->session ) ? $user->session->client->id
    : undef );
    push( @cell, defined( $user->session ) ?
    $user->session->client->clientname : undef );
    my $single_row = {
    cell => \@cell
    };
    push( @row_data, $single_row );

    }

    $self->status_ok(
    $c,
    entity => {
    page => $c->stash->{json_data}->{page},
    total => $c->stash->{json_data}->{total},
    records => $c->stash->{json_data}->{records},
    rows => \@row_data
    }
    );
    }


    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )


    On Thu, Jul 8, 2010 at 12:02 PM, Jeff Albert wrote:

    Some of your users have sessions, and thus will have a row or rows in
    the related �session� resultset � but some don�t. When you attempt to access
    $user->session->client->clientname, you�re assuming that $user->session is
    defined � but in the case of a user row with no related session row,
    $user->session won�t be defined, and you�ll raise the error you described
    when you attempt to access the methods of that resultset. Do a quick
    defined() test on $user->session before you try to use its methods, and
    you�ll be good to go. Hope that helps!



    Cheers,

    Jeff Albert



    *From:* Kyle Hall
    *Sent:* Thursday, July 08, 2010 7:57 AM
    *To:* catalyst@lists.scsys.co.uk
    *Subject:* [Catalyst] Nonsensical Problem with DBIx ResultSet



    Hello all,
    I'm the developer of a FOSS kiosk management system, Libki. I'm in the
    early stages of a complete rewrite using Catalyst for the web-based
    administration interface. This is my first time using Catalyst, but I'm very
    excited by the possibilities! I'm having a very strange issue with my
    resultsets. For example, I have three tables, a users table, a clients
    table, and a sessions table that connects the user to a client.

    I grab my users from the database, with any session/client data if the
    user is currently logged in to a client kiosk. I am prefetching the session
    and client table data.

    my $user_rs = $c->model('DB::User')->search( {}, { prefetch => { session
    => 'client' } } );

    Now I want to loop through it.

    my $row = 0;
    my @row_data;

    while ( my $user = $user_rs->next() ) {
    my $user_id = $user->id;

    warn $user->session->client->clientname;

    my $single_row = {
    cell => [
    $user->id,
    $user->username,
    $user->minutes,
    $user->status,
    $user->is_troublemaker,
    $user->session->client->clientname;
    ]
    };
    push( @row_data, $single_row );
    }


    Now, if I try to access any of the other tables, I get an error:
    [error] Caught exception in LibkiServer::Controller::Admin::REST->users
    "Can't call method "client" on an undefined value at
    /home/libki/LibkiServer/script/../lib/LibkiServer/Controller/Admin/REST.pm
    line 40."

    I don't know why I get this error, but the really crazy part is *the warn
    still works*:
    Client Name: testclient1 at
    /home/libki/LibkiServer/script/../lib/LibkiServer/Controller/Admin/REST.pm
    line 40.

    If anyone can help me out, I'd be eternally grateful.

    Thanks,
    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.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/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100708/34d7cec3/attachment.htm
  • Evan Carroll at Jul 8, 2010 at 6:27 pm

    On Thu, Jul 8, 2010 at 12:45 PM, Kyle Hall wrote:
    I figured it out. I simply had to include grid.locale-en.js *before*
    jquery.jqGrid.min.js. Again, thanks for the help.
    How is jqGrid working out for you? I was just reviewing grids.. I'm
    not too thrilled with its feature set, it doesn't seem to be able to
    transform static HTML-tables.

    --
    Evan Carroll
    System Lord of the Internets
  • Kyle Hall at Jul 9, 2010 at 11:34 am
    Indeed, jqGrid does not have the ability to transform tables afaik. However,
    for my purposes it will work great. The only real alternatives I'm aware of
    are FlexiGrid and Ingrid. It looks like Ingrid would do what you need it to
    do: http://www.reconstrukt.com/ingrid/

    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )


    On Thu, Jul 8, 2010 at 2:27 PM, Evan Carroll wrote:
    On Thu, Jul 8, 2010 at 12:45 PM, Kyle Hall wrote:
    I figured it out. I simply had to include grid.locale-en.js *before*
    jquery.jqGrid.min.js. Again, thanks for the help.
    How is jqGrid working out for you? I was just reviewing grids.. I'm
    not too thrilled with its feature set, it doesn't seem to be able to
    transform static HTML-tables.

    --
    Evan Carroll
    System Lord of the Internets

    _______________________________________________
    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/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100709/62a4ef74/attachment.htm
  • Evan Carroll at Jul 12, 2010 at 5:23 pm

    On Fri, Jul 9, 2010 at 6:34 AM, Kyle Hall wrote:
    Indeed, jqGrid does not have the ability to transform tables afaik. However,
    for my purposes it will work great. The only real alternatives I'm aware of
    are FlexiGrid and Ingrid. It looks like Ingrid would do what you need it to
    do: http://www.reconstrukt.com/ingrid/

    Kyle
    Actually, I'm using DataTables, which works great and is ThemeRoller-able.
    http://datatables.net/

    --
    Evan Carroll
    System Lord of the Internets
  • Kyle Hall at Jul 12, 2010 at 5:31 pm
    I've found it to be fantastic so far, but now I cannot get any versions of
    the search to work. I would prefer the toolbar search, but right now I'd be
    happy to have any of them.

    Kyle

    http://www.kylehall.info
    Mill Run Technology Solutions ( http://millruntech.com )
    Crawford County Federated Library System ( http://www.ccfls.org )
    Meadville Public Library ( http://www.meadvillelibrary.org )


    On Mon, Jul 12, 2010 at 1:23 PM, Evan Carroll wrote:
    On Fri, Jul 9, 2010 at 6:34 AM, Kyle Hall wrote:
    Indeed, jqGrid does not have the ability to transform tables afaik. However,
    for my purposes it will work great. The only real alternatives I'm aware of
    are FlexiGrid and Ingrid. It looks like Ingrid would do what you need it to
    do: http://www.reconstrukt.com/ingrid/

    Kyle
    Actually, I'm using DataTables, which works great and is ThemeRoller-able.
    http://datatables.net/

    --
    Evan Carroll
    System Lord of the Internets

    _______________________________________________
    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/
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100712/e0f327cd/attachment.htm
  • Evan Carroll at Jul 12, 2010 at 8:24 pm

    On Mon, Jul 12, 2010 at 12:31 PM, Kyle Hall wrote:
    I've found it to be fantastic so far, but now I cannot get any versions of
    the search to work. I would prefer the toolbar search, but right now I'd be
    happy to have any of them.

    DataTables search is awesome ;) Switch over. It also works with around
    vanilla HTML for those that don't have javascript capable browsers.
    Also better for SEO.

    --
    Evan Carroll
    System Lord of the Internets

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJul 8, '10 at 5:08p
activeJul 12, '10 at 8:24p
posts7
users2
websitecatalystframework.org
irc#catalyst

2 users in discussion

Kyle Hall: 4 posts Evan Carroll: 3 posts

People

Translate

site design / logo © 2022 Grokbase