You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Markus Grell <ta...@military.de> on 2012/01/16 16:33:43 UTC

Grid displaying database relation

Greetings!

Let me quickly introduce myself: I'm a long-time PHP developer, starting
developing PHP back mid of 90s. After a long pause I started with web
application again, but this time I had a look onto Tapestry. Even though
I'm knowing Java not very well I think that developing apps with Tapestry
is a great fun, especially in comparison to that PHP-Scripting I did in
the past.

OK, now to my first question:

I'm developing a app with a database backend, using tapestry-hibernate.
Displaying a grid with content from a database table is quite easy and
well described, but what's the best approach to display a grid with
content from a database table that has relations?
I have a list of users, each of them has role. I have the tables 'user'
and 'role'. Displaying all users in a grid was easy, but I also want to
display the role in the grid.
Any hints into the right direction?

Thanks
Markus


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Grid displaying database relation

Posted by Dragan Sahpaski <dr...@gmail.com>.
Hi Markus,
On Mon, Jan 16, 2012 at 4:33 PM, Markus Grell <ta...@military.de> wrote:

> Greetings!
>
> Let me quickly introduce myself: I'm a long-time PHP developer, starting
> developing PHP back mid of 90s. After a long pause I started with web
> application again, but this time I had a look onto Tapestry. Even though
> I'm knowing Java not very well I think that developing apps with Tapestry
> is a great fun, especially in comparison to that PHP-Scripting I did in
> the past.
>
> OK, now to my first question:
>
> I'm developing a app with a database backend, using tapestry-hibernate.
> Displaying a grid with content from a database table is quite easy and
> well described, but what's the best approach to display a grid with
> content from a database table that has relations?
> I have a list of users, each of them has role. I have the tables 'user'
> and 'role'. Displaying all users in a grid was easy, but I also want to
> display the role in the grid.
> Any hints into the right direction?
>

So I guess you have 1:m mapping between User and Role.
By default tapestry does not recognize the Role type because it does not
know how to display it (maybe you want to display the "name" attribute of
role or "title" or something else).
That is why you don't see it as a column in the Grid.

If you want tapestry to know how to display a Role do the following.
1. Contribute to the DefaultDatatypeAnalyzer the Role type so tapestry
recognizes it.
2. Contribute the display block for Role in BeanBlockSource

That's it. Next time you render the grid a role column will show up.
See [1] for explanation on how to add a property editor (almost the same as
a property display which you are looking for).

If you don't want tapestry to do this by default each time you render a
user in the grid etc.
just add a column to the grid. See the grid tapestrydoc for more examples.

<t:grid add="role" source="users" row="user" >
  <p:roleHeader>Role</p:roleHeader>
  <p:roleCell>${user.role.title}</roleCell>
</t:grid>


[1] Adding new Property Editors
http://tapestry.apache.org/beaneditform-guide.html#BeanEditFormGuide-AddingNewPropertyEditors
[2] Grid
http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/corelib/components/Grid.html


>
> Thanks
> Markus
>
>
Cheers,
Dragan Sahpaski




>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>